
<!doctype html>
<html lang="en" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
      
      
      
        <link rel="prev" href="../../04_Vue.js%E5%9F%BA%E7%A1%80/index.html">
      
      
        <link rel="next" href="../06_Servlet%E5%8F%8AFilter%E5%9F%BA%E7%A1%80%E5%AE%9E%E9%AA%8C/index.html">
      
      
      <link rel="icon" href="../../assets/images/favicon.png">
      <meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.6.5">
    
    
      
        <title>05 JSP的隐含对象实验 - 基于WEB的应用程序开发-实验指导书</title>
      
    
    
      <link rel="stylesheet" href="../../assets/stylesheets/main.8608ea7d.min.css">
      
        
        <link rel="stylesheet" href="../../assets/stylesheets/palette.06af60db.min.css">
      
      


    
    
      
    
    
      
        
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
        <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
      
    
    
      <link rel="stylesheet" href="../../assets/stylesheets/extra.css">
    
    <script>__md_scope=new URL("../..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
    
      

    
    
    
  </head>
  
  
    
    
      
    
    
    
    
    <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="purple" data-md-color-accent="indigo">
  
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#jsp" class="md-skip">
          Skip to content
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
    
      

  

<header class="md-header md-header--shadow" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="Header">
    <a href="../../index.html" title="基于WEB的应用程序开发-实验指导书" class="md-header__button md-logo" aria-label="基于WEB的应用程序开发-实验指导书" data-md-component="logo">
      
  
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            基于WEB的应用程序开发-实验指导书
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              05 JSP的隐含对象实验
            
          </span>
        </div>
      </div>
    </div>
    
      
        <form class="md-header__option" data-md-component="palette">
  
    
    
    
    <input class="md-option" data-md-color-media="" data-md-color-scheme="default" data-md-color-primary="purple" data-md-color-accent="indigo"  aria-label="夜间模式"  type="radio" name="__palette" id="__palette_0">
    
      <label class="md-header__button md-icon" title="夜间模式" for="__palette_1" hidden>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 7a5 5 0 0 1 5 5 5 5 0 0 1-5 5 5 5 0 0 1-5-5 5 5 0 0 1 5-5m0 2a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3m0-7 2.39 3.42C13.65 5.15 12.84 5 12 5s-1.65.15-2.39.42zM3.34 7l4.16-.35A7.2 7.2 0 0 0 5.94 8.5c-.44.74-.69 1.5-.83 2.29zm.02 10 1.76-3.77a7.131 7.131 0 0 0 2.38 4.14zM20.65 7l-1.77 3.79a7.02 7.02 0 0 0-2.38-4.15zm-.01 10-4.14.36c.59-.51 1.12-1.14 1.54-1.86.42-.73.69-1.5.83-2.29zM12 22l-2.41-3.44c.74.27 1.55.44 2.41.44.82 0 1.63-.17 2.37-.44z"/></svg>
      </label>
    
  
    
    
    
    <input class="md-option" data-md-color-media="" data-md-color-scheme="slate" data-md-color-primary="teal" data-md-color-accent="indigo"  aria-label="日间模式"  type="radio" name="__palette" id="__palette_1">
    
      <label class="md-header__button md-icon" title="日间模式" for="__palette_0" hidden>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m17.75 4.09-2.53 1.94.91 3.06-2.63-1.81-2.63 1.81.91-3.06-2.53-1.94L12.44 4l1.06-3 1.06 3zm3.5 6.91-1.64 1.25.59 1.98-1.7-1.17-1.7 1.17.59-1.98L15.75 11l2.06-.05L18.5 9l.69 1.95zm-2.28 4.95c.83-.08 1.72 1.1 1.19 1.85-.32.45-.66.87-1.08 1.27C15.17 23 8.84 23 4.94 19.07c-3.91-3.9-3.91-10.24 0-14.14.4-.4.82-.76 1.27-1.08.75-.53 1.93.36 1.85 1.19-.27 2.86.69 5.83 2.89 8.02a9.96 9.96 0 0 0 8.02 2.89m-1.64 2.02a12.08 12.08 0 0 1-7.8-3.47c-2.17-2.19-3.33-5-3.49-7.82-2.81 3.14-2.7 7.96.31 10.98 3.02 3.01 7.84 3.12 10.98.31"/></svg>
      </label>
    
  
</form>
      
    
    
      <script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
    
    
    
    
  </nav>
  
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
          
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    



<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href="../../index.html" title="基于WEB的应用程序开发-实验指导书" class="md-nav__button md-logo" aria-label="基于WEB的应用程序开发-实验指导书" data-md-component="logo">
      
  
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>

    </a>
    基于WEB的应用程序开发-实验指导书
  </label>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../../index.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    首页
    
  </span>
  

      </a>
    </li>
  

    
      
      
  
  
  
  
    
    
    
      
        
        
      
    
    
    <li class="md-nav__item md-nav__item--section md-nav__item--nested">
      
        
        
          
        
        <input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_2" >
        
          
          <label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="">
            
  
  <span class="md-ellipsis">
    1. 实验环境搭建
    
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="false">
          <label class="md-nav__title" for="__nav_2">
            <span class="md-nav__icon md-icon"></span>
            1. 实验环境搭建
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../../00_%E7%8E%AF%E5%A2%83%E5%BB%BA%E7%AB%8B/Java/index.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    1.1 前端环境搭建
    
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../05_%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/index.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    1.2 后端境搭建
    
  </span>
  

      </a>
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../../01_Html%E5%9F%BA%E7%A1%80/index.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    2 Html基础实验
    
  </span>
  

      </a>
    </li>
  

    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../../02_CSS%E5%9F%BA%E7%A1%80/index.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    3 CSS基础实验
    
  </span>
  

      </a>
    </li>
  

    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../../03_Javascript%E5%9F%BA%E7%A1%80/index.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    04 Javascript基础
    
  </span>
  

      </a>
    </li>
  

    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../../03_Javascript%E9%AB%98%E7%BA%A7%E5%AE%9E%E9%AA%8C/index.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    05 Javascript高级实验
    
  </span>
  

      </a>
    </li>
  

    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../../04_jQuery/index.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    06 jQuery
    
  </span>
  

      </a>
    </li>
  

    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../../04_Bootstrap/index.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    06 Bootstrap
    
  </span>
  

      </a>
    </li>
  

    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../../04_Vue.js%E5%9F%BA%E7%A1%80/index.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    06 Vue.js
    
  </span>
  

      </a>
    </li>
  

    
      
      
  
  
    
  
  
  
    <li class="md-nav__item md-nav__item--active">
      
      <input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
      
      
        
      
      
        <label class="md-nav__link md-nav__link--active" for="__toc">
          
  
  <span class="md-ellipsis">
    05 JSP的隐含对象实验
    
  </span>
  

          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <a href="index.html" class="md-nav__link md-nav__link--active">
        
  
  <span class="md-ellipsis">
    05 JSP的隐含对象实验
    
  </span>
  

      </a>
      
        

  

<nav class="md-nav md-nav--secondary" aria-label=" ">
  
  
  
    
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
       
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#1" class="md-nav__link">
    <span class="md-ellipsis">
      1 实验类型
    </span>
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#2" class="md-nav__link">
    <span class="md-ellipsis">
      2 实验目的
    </span>
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#3" class="md-nav__link">
    <span class="md-ellipsis">
      3 实验要求
    </span>
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#4" class="md-nav__link">
    <span class="md-ellipsis">
      4 实验环境
    </span>
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#5" class="md-nav__link">
    <span class="md-ellipsis">
      5 实验步骤
    </span>
  </a>
  
    <nav class="md-nav" aria-label="5 实验步骤">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_1" class="md-nav__link">
    <span class="md-ellipsis">
      创建测试工程
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#request" class="md-nav__link">
    <span class="md-ellipsis">
      request对象
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#respone" class="md-nav__link">
    <span class="md-ellipsis">
      respone对象
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#session" class="md-nav__link">
    <span class="md-ellipsis">
      session对象
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#application" class="md-nav__link">
    <span class="md-ellipsis">
      application对象
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_2" class="md-nav__link">
    <span class="md-ellipsis">
      综合
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_3" class="md-nav__link">
    <span class="md-ellipsis">
      拓展练习
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
    </ul>
  
</nav>
      
    </li>
  

    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../06_Servlet%E5%8F%8AFilter%E5%9F%BA%E7%A1%80%E5%AE%9E%E9%AA%8C/index.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    06 Servlet及Filter基础实验
    
  </span>
  

      </a>
    </li>
  

    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../07_SpringBoot%E7%BB%BC%E5%90%88%E5%AE%9E%E9%AA%8C/index.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    07 Spring Boot综合实验
    
  </span>
  

      </a>
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
              
              <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

  

<nav class="md-nav md-nav--secondary" aria-label=" ">
  
  
  
    
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
       
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#1" class="md-nav__link">
    <span class="md-ellipsis">
      1 实验类型
    </span>
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#2" class="md-nav__link">
    <span class="md-ellipsis">
      2 实验目的
    </span>
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#3" class="md-nav__link">
    <span class="md-ellipsis">
      3 实验要求
    </span>
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#4" class="md-nav__link">
    <span class="md-ellipsis">
      4 实验环境
    </span>
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#5" class="md-nav__link">
    <span class="md-ellipsis">
      5 实验步骤
    </span>
  </a>
  
    <nav class="md-nav" aria-label="5 实验步骤">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_1" class="md-nav__link">
    <span class="md-ellipsis">
      创建测试工程
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#request" class="md-nav__link">
    <span class="md-ellipsis">
      request对象
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#respone" class="md-nav__link">
    <span class="md-ellipsis">
      respone对象
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#session" class="md-nav__link">
    <span class="md-ellipsis">
      session对象
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#application" class="md-nav__link">
    <span class="md-ellipsis">
      application对象
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_2" class="md-nav__link">
    <span class="md-ellipsis">
      综合
    </span>
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_3" class="md-nav__link">
    <span class="md-ellipsis">
      拓展练习
    </span>
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
    </ul>
  
</nav>
                  </div>
                </div>
              </div>
            
          
          
            <div class="md-content" data-md-component="content">
              <article class="md-content__inner md-typeset">
                
                  



<h1 id="jsp">JSP的隐含对象实验</h1>
<h2 id="1">1 实验类型</h2>
<p>验证型，2学时，必选实验</p>
<h2 id="2">2 实验目的</h2>
<p>掌握JSP基本语法；掌握对JSP各隐含对象的功能；掌握JSP隐含对象的使用方法；理解前后端数据传输过程</p>
<h2 id="3">3 实验要求</h2>
<p>验证参考代码；修改参考代码，实现自己的设计；将关键结果截图及源代码整理成实验报告</p>
<h2 id="4">4 实验环境</h2>
<p>Windows 7 64、Open JDK 23+、Tomcat 11+、Spring Tools 4(STS4)、Visual Studio Code(VS Code)、Microsoft Edge/Chrome/Firefox等浏览器</p>
<h2 id="5">5 实验步骤</h2>
<h3 id="_1">创建测试工程</h3>
<p>为实验创建名为<code>BuiltInTest</code>的测试工程，步骤如下：</p>
<ol>
<li>
<p>创建工作目录：<code>C:/{学号}/exp6</code></p>
<blockquote>
<p>后续文件均存放在工作目录</p>
</blockquote>
</li>
<li>
<p>创建工程</p>
<p>在<strong>STS4</strong>中创建的<strong>Dynamic Web</strong>工程：<code>BuiltInTest</code></p>
<blockquote>
<p>注意：勾选<code>Generate web.xml deployment descriptor</code></p>
</blockquote>
</li>
</ol>
<h3 id="request">request对象</h3>
<p>编写两个页面，一个（RequestClient.jsp）包含表单向服务端提交数据，另一个（RequestServer.jsp）接收该表单提交的数据，参考步骤如下：</p>
<ol>
<li>
<p>创建表单页面<code>webapp/RequestClient.jsp</code>，通过该页面提交参数给<code>RequestServer.jsp</code>，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/RequestClient.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-0-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-0-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-0-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-0-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-0-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-0-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-0-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-0-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-0-10">10</a></span>
<span class="normal"><a href="#__codelineno-0-11">11</a></span>
<span class="normal"><a href="#__codelineno-0-12">12</a></span>
<span class="normal"><a href="#__codelineno-0-13">13</a></span>
<span class="normal"><a href="#__codelineno-0-14">14</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-0-1" name="__codelineno-0-1"></a><span class="err">&lt;</span>%@ page contentType=&quot;text/html;charset=utf-8&quot; %&gt;
<a id="__codelineno-0-2" name="__codelineno-0-2"></a><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<a id="__codelineno-0-3" name="__codelineno-0-3"></a><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-0-4" name="__codelineno-0-4"></a><span class="p">&lt;</span><span class="nt">meta</span> <span class="na">charset</span><span class="o">=</span><span class="s">&quot;utf-8&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-0-5" name="__codelineno-0-5"></a><span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-0-6" name="__codelineno-0-6"></a>
<a id="__codelineno-0-7" name="__codelineno-0-7"></a><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-0-8" name="__codelineno-0-8"></a>  <span class="p">&lt;</span><span class="nt">form</span> <span class="na">action</span><span class="o">=</span><span class="s">&quot;RequestServer.jsp&quot;</span> <span class="na">method</span><span class="o">=</span><span class="s">&quot;POST&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;form&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-0-9" name="__codelineno-0-9"></a>    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;text&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;boy&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-0-10" name="__codelineno-0-10"></a>    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;submit&quot;</span> <span class="na">value</span><span class="o">=</span><span class="s">&quot;Enter&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;submit&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-0-11" name="__codelineno-0-11"></a>  <span class="p">&lt;/</span><span class="nt">form</span><span class="p">&gt;</span>
<a id="__codelineno-0-12" name="__codelineno-0-12"></a><span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-0-13" name="__codelineno-0-13"></a>
<a id="__codelineno-0-14" name="__codelineno-0-14"></a><span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建接收页面<code>webapp/RequestServer.jsp</code>处理<code>RequestClient.jsp</code>文件提交的参数，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/RequestServer.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-1-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-1-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-1-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-1-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-1-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-1-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-1-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-1-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-1-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-1-10">10</a></span>
<span class="normal"><a href="#__codelineno-1-11">11</a></span>
<span class="normal"><a href="#__codelineno-1-12">12</a></span>
<span class="normal"><a href="#__codelineno-1-13">13</a></span>
<span class="normal"><a href="#__codelineno-1-14">14</a></span>
<span class="normal"><a href="#__codelineno-1-15">15</a></span>
<span class="normal"><a href="#__codelineno-1-16">16</a></span>
<span class="normal"><a href="#__codelineno-1-17">17</a></span>
<span class="normal"><a href="#__codelineno-1-18">18</a></span>
<span class="normal"><a href="#__codelineno-1-19">19</a></span>
<span class="normal"><a href="#__codelineno-1-20">20</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-1-1" name="__codelineno-1-1"></a><span class="err">&lt;</span>%@ page contentType=&quot;text/html;charset=utf-8&quot; %&gt;
<a id="__codelineno-1-2" name="__codelineno-1-2"></a><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<a id="__codelineno-1-3" name="__codelineno-1-3"></a><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-1-4" name="__codelineno-1-4"></a><span class="p">&lt;</span><span class="nt">meta</span> <span class="na">charset</span><span class="o">=</span><span class="s">&quot;utf-8&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-1-5" name="__codelineno-1-5"></a><span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-1-6" name="__codelineno-1-6"></a>
<a id="__codelineno-1-7" name="__codelineno-1-7"></a><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-1-8" name="__codelineno-1-8"></a>  <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-1-9" name="__codelineno-1-9"></a>    获取文本框提交的信息：
<a id="__codelineno-1-10" name="__codelineno-1-10"></a>    <span class="err">&lt;</span>% String textContent=request.getParameter(&quot;boy&quot;); %&gt;<span class="p">&lt;</span><span class="nt">br</span><span class="p">&gt;</span>
<a id="__codelineno-1-11" name="__codelineno-1-11"></a>    <span class="err">&lt;</span>%=textContent%&gt;
<a id="__codelineno-1-12" name="__codelineno-1-12"></a>  <span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-1-13" name="__codelineno-1-13"></a>  <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-1-14" name="__codelineno-1-14"></a>    获取按钮的名字：
<a id="__codelineno-1-15" name="__codelineno-1-15"></a>    <span class="err">&lt;</span>% String buttonName=request.getParameter(&quot;submit&quot;); %&gt;<span class="p">&lt;</span><span class="nt">br</span><span class="p">&gt;</span>
<a id="__codelineno-1-16" name="__codelineno-1-16"></a>    <span class="err">&lt;</span>%=buttonName%&gt;
<a id="__codelineno-1-17" name="__codelineno-1-17"></a>  <span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-1-18" name="__codelineno-1-18"></a><span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-1-19" name="__codelineno-1-19"></a>
<a id="__codelineno-1-20" name="__codelineno-1-20"></a><span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>访问表单页面；在浏览器中访问<code>http://localhost:8080/BuiltInTest/RequestClient.jsp</code></p>
<!--
    ??? tip "运行结果"
        <iframe src="./src/BuiltInTestResult/RequestClient.jsp.html" frameborder="0" width="100%" height="50"></iframe>
-->
</li>
<li>
<p>提交数据；在文本框中输入任意字符串（如：Jack）后点击<strong>Enter</strong>观察浏览器地址栏及页面内容变化</p>
<!--
    ??? tip "运行结果"
        <iframe src="./src/BuiltInTestResult/RequestServer.jsp.html" frameborder="0" width="100%" height="150"></iframe>
-->
</li>
</ol>
<h3 id="respone">respone对象</h3>
<p>通过登录页面（ResponseLogin.jsp）向控制页面（ResponseCheck.jsp）提交用户认证信息，控制页面根据预先设定的规则将用户引导到不同页面（ResponseFail.jsp），参考步骤如下：</p>
<ol>
<li>
<p>创建登录页面<code>/webapp/ResponseLogin.jsp</code>，实现登录界面，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/ResponseLogin.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-2-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-2-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-2-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-2-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-2-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-2-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-2-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-2-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-2-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-2-10">10</a></span>
<span class="normal"><a href="#__codelineno-2-11">11</a></span>
<span class="normal"><a href="#__codelineno-2-12">12</a></span>
<span class="normal"><a href="#__codelineno-2-13">13</a></span>
<span class="normal"><a href="#__codelineno-2-14">14</a></span>
<span class="normal"><a href="#__codelineno-2-15">15</a></span>
<span class="normal"><a href="#__codelineno-2-16">16</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-2-1" name="__codelineno-2-1"></a><span class="err">&lt;</span>%@ page contentType=&quot;text/html;charset=utf-8&quot; %&gt;
<a id="__codelineno-2-2" name="__codelineno-2-2"></a><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<a id="__codelineno-2-3" name="__codelineno-2-3"></a><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-2-4" name="__codelineno-2-4"></a><span class="p">&lt;</span><span class="nt">meta</span> <span class="na">charset</span><span class="o">=</span><span class="s">&quot;utf-8&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-2-5" name="__codelineno-2-5"></a><span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-2-6" name="__codelineno-2-6"></a>
<a id="__codelineno-2-7" name="__codelineno-2-7"></a><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-2-8" name="__codelineno-2-8"></a>  填写姓名：
<a id="__codelineno-2-9" name="__codelineno-2-9"></a>  <span class="p">&lt;</span><span class="nt">br</span><span class="p">&gt;</span>
<a id="__codelineno-2-10" name="__codelineno-2-10"></a>  <span class="p">&lt;</span><span class="nt">form</span> <span class="na">action</span><span class="o">=</span><span class="s">&quot;ResponseCheck.jsp&quot;</span> <span class="na">method</span><span class="o">=</span><span class="s">&quot;GET&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;form&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-2-11" name="__codelineno-2-11"></a>    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;text&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;name&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-2-12" name="__codelineno-2-12"></a>    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;submit&quot;</span> <span class="na">value</span><span class="o">=</span><span class="s">&quot;Enter&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-2-13" name="__codelineno-2-13"></a>  <span class="p">&lt;/</span><span class="nt">form</span><span class="p">&gt;</span>
<a id="__codelineno-2-14" name="__codelineno-2-14"></a><span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-2-15" name="__codelineno-2-15"></a>
<a id="__codelineno-2-16" name="__codelineno-2-16"></a><span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建控制页面<code>/webapp/ResponseCheck.jsp</code>，实现认证信息检查，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/ResponseCheck.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-3-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-3-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-3-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-3-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-3-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-3-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-3-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-3-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-3-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-3-10">10</a></span>
<span class="normal"><a href="#__codelineno-3-11">11</a></span>
<span class="normal"><a href="#__codelineno-3-12">12</a></span>
<span class="normal"><a href="#__codelineno-3-13">13</a></span>
<span class="normal"><a href="#__codelineno-3-14">14</a></span>
<span class="normal"><a href="#__codelineno-3-15">15</a></span>
<span class="normal"><a href="#__codelineno-3-16">16</a></span>
<span class="normal"><a href="#__codelineno-3-17">17</a></span>
<span class="normal"><a href="#__codelineno-3-18">18</a></span>
<span class="normal"><a href="#__codelineno-3-19">19</a></span>
<span class="normal"><a href="#__codelineno-3-20">20</a></span>
<span class="normal"><a href="#__codelineno-3-21">21</a></span>
<span class="normal"><a href="#__codelineno-3-22">22</a></span>
<span class="normal"><a href="#__codelineno-3-23">23</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-3-1" name="__codelineno-3-1"></a><span class="err">&lt;</span>%@ page contentType=&quot;text/html;charset=utf-8&quot;%&gt;
<a id="__codelineno-3-2" name="__codelineno-3-2"></a><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<a id="__codelineno-3-3" name="__codelineno-3-3"></a><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-3-4" name="__codelineno-3-4"></a><span class="p">&lt;</span><span class="nt">meta</span> <span class="na">charset</span><span class="o">=</span><span class="s">&quot;utf-8&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-3-5" name="__codelineno-3-5"></a><span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-3-6" name="__codelineno-3-6"></a><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-3-7" name="__codelineno-3-7"></a>  <span class="err">&lt;</span>%
<a id="__codelineno-3-8" name="__codelineno-3-8"></a>  String str = null;
<a id="__codelineno-3-9" name="__codelineno-3-9"></a>  str = request.getParameter(&quot;name&quot;);
<a id="__codelineno-3-10" name="__codelineno-3-10"></a>  if (str == null) {
<a id="__codelineno-3-11" name="__codelineno-3-11"></a>    str = &quot;&quot;;
<a id="__codelineno-3-12" name="__codelineno-3-12"></a>  }
<a id="__codelineno-3-13" name="__codelineno-3-13"></a>  byte b[] = str.getBytes(&quot;ISO-8859-1&quot;);
<a id="__codelineno-3-14" name="__codelineno-3-14"></a>  str = new String(b);
<a id="__codelineno-3-15" name="__codelineno-3-15"></a>  if (str.equals(&quot;&quot;)) {
<a id="__codelineno-3-16" name="__codelineno-3-16"></a>    response.sendRedirect(&quot;ResponseFail.jsp&quot;);
<a id="__codelineno-3-17" name="__codelineno-3-17"></a>  } else {
<a id="__codelineno-3-18" name="__codelineno-3-18"></a>    out.print(&quot;欢迎您来到本网页！&quot;);
<a id="__codelineno-3-19" name="__codelineno-3-19"></a>    out.print(str);
<a id="__codelineno-3-20" name="__codelineno-3-20"></a>  }
<a id="__codelineno-3-21" name="__codelineno-3-21"></a>  %&gt;
<a id="__codelineno-3-22" name="__codelineno-3-22"></a><span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-3-23" name="__codelineno-3-23"></a><span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建失败页面<code>/webapp/ResponseFail.jsp</code>，提示认证失败信息，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/ResponseFail.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-4-1">1</a></span>
<span class="normal"><a href="#__codelineno-4-2">2</a></span>
<span class="normal"><a href="#__codelineno-4-3">3</a></span>
<span class="normal"><a href="#__codelineno-4-4">4</a></span>
<span class="normal"><a href="#__codelineno-4-5">5</a></span>
<span class="normal"><a href="#__codelineno-4-6">6</a></span>
<span class="normal"><a href="#__codelineno-4-7">7</a></span>
<span class="normal"><a href="#__codelineno-4-8">8</a></span>
<span class="normal"><a href="#__codelineno-4-9">9</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-4-1" name="__codelineno-4-1"></a><span class="err">&lt;</span>%@ page contentType=&quot;text/html;charset=utf-8&quot; %&gt;
<a id="__codelineno-4-2" name="__codelineno-4-2"></a><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<a id="__codelineno-4-3" name="__codelineno-4-3"></a><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-4-4" name="__codelineno-4-4"></a><span class="p">&lt;</span><span class="nt">meta</span> <span class="na">charset</span><span class="o">=</span><span class="s">&quot;utf-8&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-4-5" name="__codelineno-4-5"></a><span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-4-6" name="__codelineno-4-6"></a><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-4-7" name="__codelineno-4-7"></a>  请输入用户名！
<a id="__codelineno-4-8" name="__codelineno-4-8"></a><span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-4-9" name="__codelineno-4-9"></a><span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>测试；在浏览器中打开<code>http://localhost:8080/BuiltInTest/ResponseLogin.jsp</code>，输入任一字符串（如：Jack）点击<strong>Enter</strong>，观察地址栏和页面的变化</p>
</li>
</ol>
<h3 id="session">session对象</h3>
<p>创建包含跳转链接的页面，在不同页面之间跳转过程中，观察session id的变化，参考步骤如下：</p>
<ol>
<li>
<p>创建初始页面<code>SessionClient.jsp</code>，作为入口显示当前session的id，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/SessionClient.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-5-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-5-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-5-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-5-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-5-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-5-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-5-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-5-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-5-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-5-10">10</a></span>
<span class="normal"><a href="#__codelineno-5-11">11</a></span>
<span class="normal"><a href="#__codelineno-5-12">12</a></span>
<span class="normal"><a href="#__codelineno-5-13">13</a></span>
<span class="normal"><a href="#__codelineno-5-14">14</a></span>
<span class="normal"><a href="#__codelineno-5-15">15</a></span>
<span class="normal"><a href="#__codelineno-5-16">16</a></span>
<span class="normal"><a href="#__codelineno-5-17">17</a></span>
<span class="normal"><a href="#__codelineno-5-18">18</a></span>
<span class="normal"><a href="#__codelineno-5-19">19</a></span>
<span class="normal"><a href="#__codelineno-5-20">20</a></span>
<span class="normal"><a href="#__codelineno-5-21">21</a></span>
<span class="normal"><a href="#__codelineno-5-22">22</a></span>
<span class="normal"><a href="#__codelineno-5-23">23</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-5-1" name="__codelineno-5-1"></a><span class="err">&lt;</span>%@ page contentType=&quot;text/html;charset=utf-8&quot; %&gt;
<a id="__codelineno-5-2" name="__codelineno-5-2"></a><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<a id="__codelineno-5-3" name="__codelineno-5-3"></a><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-5-4" name="__codelineno-5-4"></a><span class="p">&lt;</span><span class="nt">meta</span> <span class="na">charset</span><span class="o">=</span><span class="s">&quot;utf-8&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-5-5" name="__codelineno-5-5"></a><span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-5-6" name="__codelineno-5-6"></a>
<a id="__codelineno-5-7" name="__codelineno-5-7"></a><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-5-8" name="__codelineno-5-8"></a>  <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-5-9" name="__codelineno-5-9"></a>    <span class="err">&lt;</span>% String s=session.getId(); %&gt;
<a id="__codelineno-5-10" name="__codelineno-5-10"></a>  <span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-5-11" name="__codelineno-5-11"></a>  <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-5-12" name="__codelineno-5-12"></a>    您的session对象的ID是：<span class="p">&lt;</span><span class="nt">br</span><span class="p">&gt;</span>
<a id="__codelineno-5-13" name="__codelineno-5-13"></a>    <span class="err">&lt;</span>%=s%&gt;
<a id="__codelineno-5-14" name="__codelineno-5-14"></a>  <span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-5-15" name="__codelineno-5-15"></a>  <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>输入你的姓名连接到tom.jsp
<a id="__codelineno-5-16" name="__codelineno-5-16"></a>  <span class="p">&lt;</span><span class="nt">form</span> <span class="na">action</span><span class="o">=</span><span class="s">&quot;SessionTom.jsp&quot;</span> <span class="na">method</span><span class="o">=</span><span class="s">&quot;POST&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;form&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-5-17" name="__codelineno-5-17"></a>    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;text&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;name&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-5-18" name="__codelineno-5-18"></a>    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;submit&quot;</span> <span class="na">value</span><span class="o">=</span><span class="s">&quot;送出&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">submit</span><span class="p">&gt;</span>
<a id="__codelineno-5-19" name="__codelineno-5-19"></a>  <span class="p">&lt;/</span><span class="nt">form</span><span class="p">&gt;</span>
<a id="__codelineno-5-20" name="__codelineno-5-20"></a>  <span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-5-21" name="__codelineno-5-21"></a><span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-5-22" name="__codelineno-5-22"></a>
<a id="__codelineno-5-23" name="__codelineno-5-23"></a><span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建中间页面<code>/webapp/SessionTom.jsp</code>，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/SessionTom.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-6-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-6-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-6-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-6-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-6-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-6-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-6-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-6-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-6-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-6-10">10</a></span>
<span class="normal"><a href="#__codelineno-6-11">11</a></span>
<span class="normal"><a href="#__codelineno-6-12">12</a></span>
<span class="normal"><a href="#__codelineno-6-13">13</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-6-1" name="__codelineno-6-1"></a><span class="err">&lt;</span>%@ page contentType=&quot;text/html;charset=utf-8&quot;%&gt;
<a id="__codelineno-6-2" name="__codelineno-6-2"></a><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<a id="__codelineno-6-3" name="__codelineno-6-3"></a><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-6-4" name="__codelineno-6-4"></a><span class="p">&lt;</span><span class="nt">meta</span> <span class="na">charset</span><span class="o">=</span><span class="s">&quot;utf-8&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-6-5" name="__codelineno-6-5"></a><span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-6-6" name="__codelineno-6-6"></a><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-6-7" name="__codelineno-6-7"></a>  <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>我是Tom页面<span class="err">&lt;</span>%String s = session.getId();%&gt;<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-6-8" name="__codelineno-6-8"></a>  <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>您的在Tom页面中的session对象的ID是：<span class="err">&lt;</span>%=s%&gt;<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-6-9" name="__codelineno-6-9"></a>  <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>点击超链接，连接到Jerry的页面。 <span class="p">&lt;</span><span class="nt">br</span><span class="p">&gt;</span> 
<a id="__codelineno-6-10" name="__codelineno-6-10"></a>    <span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;SessionJerry.jsp&quot;</span><span class="p">&gt;</span>欢迎到Jerry屋来！<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
<a id="__codelineno-6-11" name="__codelineno-6-11"></a>  <span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-6-12" name="__codelineno-6-12"></a><span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-6-13" name="__codelineno-6-13"></a><span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建结束页面<code>/webapp/SessionJerry.jsp</code>，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/SessionJerry.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-7-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-7-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-7-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-7-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-7-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-7-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-7-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-7-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-7-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-7-10">10</a></span>
<span class="normal"><a href="#__codelineno-7-11">11</a></span>
<span class="normal"><a href="#__codelineno-7-12">12</a></span>
<span class="normal"><a href="#__codelineno-7-13">13</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-7-1" name="__codelineno-7-1"></a><span class="err">&lt;</span>%@ page contentType=&quot;text/html;charset=utf-8&quot;%&gt;
<a id="__codelineno-7-2" name="__codelineno-7-2"></a><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<a id="__codelineno-7-3" name="__codelineno-7-3"></a><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-7-4" name="__codelineno-7-4"></a><span class="p">&lt;</span><span class="nt">meta</span> <span class="na">charset</span><span class="o">=</span><span class="s">&quot;utf-8&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-7-5" name="__codelineno-7-5"></a><span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-7-6" name="__codelineno-7-6"></a><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-7-7" name="__codelineno-7-7"></a>  <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>我是Jerry页面<span class="err">&lt;</span>%String s = session.getId();%&gt;<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-7-8" name="__codelineno-7-8"></a>  <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>您在Jerry页面中的session对象的ID是：<span class="err">&lt;</span>%=s%&gt;<span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-7-9" name="__codelineno-7-9"></a>  <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>点击超链接，连接到session的页面。 <span class="p">&lt;</span><span class="nt">br</span><span class="p">&gt;</span>
<a id="__codelineno-7-10" name="__codelineno-7-10"></a>    <span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;SessionClient.jsp&quot;</span><span class="p">&gt;</span>欢迎到session屋来！<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
<a id="__codelineno-7-11" name="__codelineno-7-11"></a>  <span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-7-12" name="__codelineno-7-12"></a><span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-7-13" name="__codelineno-7-13"></a><span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>测试；访问<code>http://localhost:8080/BuiltInTest/SessionClient.jsp</code>，观察并记住当前sesson的id，分别点击<code>Tom</code>和<code>Jerry</code>链接并观察session id的变化</p>
</li>
</ol>
<h3 id="application">application对象</h3>
<p>在<strong>留言板页面</strong>（ApplicationSubmit.jsp）中输入留言信息，在<strong>记录页面</strong>（ApplicationMessagePane.jsp）全局记录留言信息，在<strong>查看页面</strong>（ApplicationShowMessage.jsp）中查看记录信息，参考步骤如下：</p>
<ol>
<li>
<p>创建留言板页面<code>webapp/ApplicationSubmit.jsp</code>，用于在前端采集信息，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/ApplicationSubmit.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-8-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-8-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-8-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-8-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-8-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-8-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-8-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-8-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-8-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-8-10">10</a></span>
<span class="normal"><a href="#__codelineno-8-11">11</a></span>
<span class="normal"><a href="#__codelineno-8-12">12</a></span>
<span class="normal"><a href="#__codelineno-8-13">13</a></span>
<span class="normal"><a href="#__codelineno-8-14">14</a></span>
<span class="normal"><a href="#__codelineno-8-15">15</a></span>
<span class="normal"><a href="#__codelineno-8-16">16</a></span>
<span class="normal"><a href="#__codelineno-8-17">17</a></span>
<span class="normal"><a href="#__codelineno-8-18">18</a></span>
<span class="normal"><a href="#__codelineno-8-19">19</a></span>
<span class="normal"><a href="#__codelineno-8-20">20</a></span>
<span class="normal"><a href="#__codelineno-8-21">21</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-8-1" name="__codelineno-8-1"></a><span class="err">&lt;</span>%@ page contentType=&quot;text/html;charset=utf-8&quot;%&gt;
<a id="__codelineno-8-2" name="__codelineno-8-2"></a><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<a id="__codelineno-8-3" name="__codelineno-8-3"></a><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-8-4" name="__codelineno-8-4"></a><span class="p">&lt;</span><span class="nt">meta</span> <span class="na">charset</span><span class="o">=</span><span class="s">&quot;utf-8&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-8-5" name="__codelineno-8-5"></a><span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-8-6" name="__codelineno-8-6"></a><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-8-7" name="__codelineno-8-7"></a>  <span class="p">&lt;</span><span class="nt">form</span> <span class="na">action</span><span class="o">=</span><span class="s">&quot;ApplicationMessagePane.jsp&quot;</span> <span class="na">method</span><span class="o">=</span><span class="s">&quot;post&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;MessagePane&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-8-8" name="__codelineno-8-8"></a>    <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>输入您的名字： <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;text&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;peopleName&quot;</span><span class="p">&gt;&lt;</span><span class="nt">br</span><span class="p">&gt;&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-8-9" name="__codelineno-8-9"></a>    <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>输入您的留言标题： <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;text&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;Title&quot;</span><span class="p">&gt;&lt;</span><span class="nt">br</span><span class="p">&gt;&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-8-10" name="__codelineno-8-10"></a>    <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>输入您的留言：<span class="p">&lt;</span><span class="nt">br</span><span class="p">&gt;</span>
<a id="__codelineno-8-11" name="__codelineno-8-11"></a>      <span class="p">&lt;</span><span class="nt">textarea</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;messages&quot;</span> <span class="na">ROWs</span><span class="o">=</span><span class="s">&quot;10&quot;</span> <span class="na">COLS</span><span class="o">=</span><span class="s">36</span> <span class="na">WRAP</span><span class="o">=</span><span class="s">&quot;physical&quot;</span><span class="p">&gt;&lt;/</span><span class="nt">textarea</span><span class="p">&gt;</span>
<a id="__codelineno-8-12" name="__codelineno-8-12"></a>      <span class="p">&lt;</span><span class="nt">br</span><span class="p">&gt;</span> 
<a id="__codelineno-8-13" name="__codelineno-8-13"></a>      <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;submit&quot;</span> <span class="na">value</span><span class="o">=</span><span class="s">&quot;提交信息&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;submit&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-8-14" name="__codelineno-8-14"></a>    <span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<a id="__codelineno-8-15" name="__codelineno-8-15"></a>  <span class="p">&lt;/</span><span class="nt">form</span><span class="p">&gt;</span>
<a id="__codelineno-8-16" name="__codelineno-8-16"></a>
<a id="__codelineno-8-17" name="__codelineno-8-17"></a>  <span class="p">&lt;</span><span class="nt">form</span> <span class="na">action</span><span class="o">=</span><span class="s">&quot;ApplicationShowMessage.jsp&quot;</span> <span class="na">method</span><span class="o">=</span><span class="s">&quot;post&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;ShowMessage&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-8-18" name="__codelineno-8-18"></a>    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;submit&quot;</span> <span class="na">value</span><span class="o">=</span><span class="s">&quot;查看留言板&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;look&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-8-19" name="__codelineno-8-19"></a>  <span class="p">&lt;/</span><span class="nt">form</span><span class="p">&gt;</span>
<a id="__codelineno-8-20" name="__codelineno-8-20"></a><span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-8-21" name="__codelineno-8-21"></a><span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建记录页面<code>/webapp/ApplicationMessagePane.jsp</code>，用于在application中记录前端采集的信息，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/ApplicationMessagePane.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-9-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-9-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-9-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-9-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-9-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-9-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-9-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-9-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-9-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-9-10">10</a></span>
<span class="normal"><a href="#__codelineno-9-11">11</a></span>
<span class="normal"><a href="#__codelineno-9-12">12</a></span>
<span class="normal"><a href="#__codelineno-9-13">13</a></span>
<span class="normal"><a href="#__codelineno-9-14">14</a></span>
<span class="normal"><a href="#__codelineno-9-15">15</a></span>
<span class="normal"><a href="#__codelineno-9-16">16</a></span>
<span class="normal"><a href="#__codelineno-9-17">17</a></span>
<span class="normal"><a href="#__codelineno-9-18">18</a></span>
<span class="normal"><a href="#__codelineno-9-19">19</a></span>
<span class="normal"><a href="#__codelineno-9-20">20</a></span>
<span class="normal"><a href="#__codelineno-9-21">21</a></span>
<span class="normal"><a href="#__codelineno-9-22">22</a></span>
<span class="normal"><a href="#__codelineno-9-23">23</a></span>
<span class="normal"><a href="#__codelineno-9-24">24</a></span>
<span class="normal"><a href="#__codelineno-9-25">25</a></span>
<span class="normal"><a href="#__codelineno-9-26">26</a></span>
<span class="normal"><a href="#__codelineno-9-27">27</a></span>
<span class="normal"><a href="#__codelineno-9-28">28</a></span>
<span class="normal"><a href="#__codelineno-9-29">29</a></span>
<span class="normal"><a href="#__codelineno-9-30">30</a></span>
<span class="normal"><a href="#__codelineno-9-31">31</a></span>
<span class="normal"><a href="#__codelineno-9-32">32</a></span>
<span class="normal"><a href="#__codelineno-9-33">33</a></span>
<span class="normal"><a href="#__codelineno-9-34">34</a></span>
<span class="normal"><a href="#__codelineno-9-35">35</a></span>
<span class="normal"><a href="#__codelineno-9-36">36</a></span>
<span class="normal"><a href="#__codelineno-9-37">37</a></span>
<span class="normal"><a href="#__codelineno-9-38">38</a></span>
<span class="normal"><a href="#__codelineno-9-39">39</a></span>
<span class="normal"><a href="#__codelineno-9-40">40</a></span>
<span class="normal"><a href="#__codelineno-9-41">41</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-9-1" name="__codelineno-9-1"></a><span class="err">&lt;</span>%@ page contentType=&quot;text/html;charset=utf-8&quot;%&gt;
<a id="__codelineno-9-2" name="__codelineno-9-2"></a><span class="err">&lt;</span>%@ page import=&quot;java.util.*&quot;%&gt;
<a id="__codelineno-9-3" name="__codelineno-9-3"></a><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<a id="__codelineno-9-4" name="__codelineno-9-4"></a><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-9-5" name="__codelineno-9-5"></a><span class="p">&lt;</span><span class="nt">meta</span> <span class="na">charset</span><span class="o">=</span><span class="s">&quot;utf-8&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-9-6" name="__codelineno-9-6"></a><span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-9-7" name="__codelineno-9-7"></a><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-9-8" name="__codelineno-9-8"></a>  <span class="err">&lt;</span>%!
<a id="__codelineno-9-9" name="__codelineno-9-9"></a>    Vector v = new Vector();
<a id="__codelineno-9-10" name="__codelineno-9-10"></a>    int i = 0;
<a id="__codelineno-9-11" name="__codelineno-9-11"></a>    ServletContext application;
<a id="__codelineno-9-12" name="__codelineno-9-12"></a>
<a id="__codelineno-9-13" name="__codelineno-9-13"></a>    synchronized void sendMessage(String s) {
<a id="__codelineno-9-14" name="__codelineno-9-14"></a>      application = getServletContext();
<a id="__codelineno-9-15" name="__codelineno-9-15"></a>      i++;
<a id="__codelineno-9-16" name="__codelineno-9-16"></a>      v.add(&quot;No.&quot; + i + &quot;,&quot; + s);
<a id="__codelineno-9-17" name="__codelineno-9-17"></a>      application.setAttribute(&quot;Mess&quot;, v);
<a id="__codelineno-9-18" name="__codelineno-9-18"></a>    }
<a id="__codelineno-9-19" name="__codelineno-9-19"></a>  %&gt;
<a id="__codelineno-9-20" name="__codelineno-9-20"></a>
<a id="__codelineno-9-21" name="__codelineno-9-21"></a>  <span class="err">&lt;</span>%
<a id="__codelineno-9-22" name="__codelineno-9-22"></a>    request.setCharacterEncoding(&quot;utf-8&quot;);
<a id="__codelineno-9-23" name="__codelineno-9-23"></a>    String name = request.getParameter(&quot;peopleName&quot;);
<a id="__codelineno-9-24" name="__codelineno-9-24"></a>    String title = request.getParameter(&quot;Title&quot;);
<a id="__codelineno-9-25" name="__codelineno-9-25"></a>    String messages = request.getParameter(&quot;messages&quot;);
<a id="__codelineno-9-26" name="__codelineno-9-26"></a>    if (name == null) {
<a id="__codelineno-9-27" name="__codelineno-9-27"></a>      name = &quot;guest&quot; + (int) (Math.random() * 10000);
<a id="__codelineno-9-28" name="__codelineno-9-28"></a>    }
<a id="__codelineno-9-29" name="__codelineno-9-29"></a>    if (title == null) {
<a id="__codelineno-9-30" name="__codelineno-9-30"></a>      title = &quot;无标题&quot;;
<a id="__codelineno-9-31" name="__codelineno-9-31"></a>    }
<a id="__codelineno-9-32" name="__codelineno-9-32"></a>    if (messages == null) {
<a id="__codelineno-9-33" name="__codelineno-9-33"></a>      messages = &quot;无信息&quot;;
<a id="__codelineno-9-34" name="__codelineno-9-34"></a>    }
<a id="__codelineno-9-35" name="__codelineno-9-35"></a>    String s = &quot;Name:&quot; + name + &quot;#&quot; + &quot;Title:&quot; + title + &quot;#&quot; + &quot;Content:&quot; + &quot;#&quot; + messages;
<a id="__codelineno-9-36" name="__codelineno-9-36"></a>    sendMessage(s);
<a id="__codelineno-9-37" name="__codelineno-9-37"></a>    out.print(&quot;您的信息已经提交！&quot;);
<a id="__codelineno-9-38" name="__codelineno-9-38"></a>  %&gt;
<a id="__codelineno-9-39" name="__codelineno-9-39"></a>  <span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;ApplicationSubmit.jsp&quot;</span><span class="p">&gt;</span>返回<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
<a id="__codelineno-9-40" name="__codelineno-9-40"></a><span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-9-41" name="__codelineno-9-41"></a><span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建查看页面<code>/webapp/ApplicationShowMessage.jsp</code>，用于查看application中存储的信息，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/ApplicationShowMessage.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-10-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-10-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-10-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-10-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-10-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-10-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-10-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-10-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-10-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-10-10">10</a></span>
<span class="normal"><a href="#__codelineno-10-11">11</a></span>
<span class="normal"><a href="#__codelineno-10-12">12</a></span>
<span class="normal"><a href="#__codelineno-10-13">13</a></span>
<span class="normal"><a href="#__codelineno-10-14">14</a></span>
<span class="normal"><a href="#__codelineno-10-15">15</a></span>
<span class="normal"><a href="#__codelineno-10-16">16</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-10-1" name="__codelineno-10-1"></a><span class="err">&lt;</span>%@ page contentType=&quot;text/html;charset=utf-8&quot;%&gt;
<a id="__codelineno-10-2" name="__codelineno-10-2"></a><span class="err">&lt;</span>%@ page import=&quot;java.util.*&quot;%&gt;
<a id="__codelineno-10-3" name="__codelineno-10-3"></a><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<a id="__codelineno-10-4" name="__codelineno-10-4"></a><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-10-5" name="__codelineno-10-5"></a><span class="p">&lt;</span><span class="nt">meta</span> <span class="na">charset</span><span class="o">=</span><span class="s">&quot;utf-8&quot;</span><span class="p">&gt;</span>
<a id="__codelineno-10-6" name="__codelineno-10-6"></a><span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<a id="__codelineno-10-7" name="__codelineno-10-7"></a><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-10-8" name="__codelineno-10-8"></a>  <span class="err">&lt;</span>%
<a id="__codelineno-10-9" name="__codelineno-10-9"></a>  Vector v = (Vector) application.getAttribute(&quot;Mess&quot;);
<a id="__codelineno-10-10" name="__codelineno-10-10"></a>  for (int i = 0; i <span class="p">&lt;</span> <span class="nt">v.size</span><span class="err">();</span> <span class="na">i</span><span class="err">++)</span> <span class="err">{</span>
<a id="__codelineno-10-11" name="__codelineno-10-11"></a>    <span class="na">String</span> <span class="na">message </span><span class="o">=</span> <span class="s">(String)</span> <span class="na">v</span><span class="err">.</span><span class="na">elementAt</span><span class="err">(</span><span class="na">i</span><span class="err">);</span>
<a id="__codelineno-10-12" name="__codelineno-10-12"></a>    <span class="na">out</span><span class="err">.</span><span class="na">print</span><span class="err">(&quot;&lt;</span><span class="na">br</span><span class="p">&gt;</span>&quot; + message);
<a id="__codelineno-10-13" name="__codelineno-10-13"></a>  }
<a id="__codelineno-10-14" name="__codelineno-10-14"></a>  %&gt;
<a id="__codelineno-10-15" name="__codelineno-10-15"></a><span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<a id="__codelineno-10-16" name="__codelineno-10-16"></a><span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>测试留言；在浏览器中访问<code>http://localhost:8080/BuiltInTest/ApplicationSubmit.jsp</code>，并在表单中填写信息并提交</p>
<!---
    ??? tip "运行结果"
        <iframe src="./src/BuiltInTestResult/ApplicationMessagePane.jsp.html" frameborder="0" width="100%" height="100"></iframe>
-->
</li>
<li>
<p>查看留言；访问返回<code>ApplicationSubmit.jsp</code>页面，点击<strong>查看留言板</strong>，观察留言信息是否完整</p>
<!--
    ??? tip "运行结果"
        <iframe src="./src/BuiltInTestResult/ApplicationShowMessage.jsp.html" frameborder="0" width="100%" height="100"></iframe>
-->
</li>
</ol>
<h3 id="_2">综合</h3>
<p>使用JSP实现学生表的增、删、改、查操作，主要页面功能如下：</p>
<table>
<thead>
<tr>
<th>url</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>/stu/add_view.jsp</code></td>
<td>添加学生页面，成功后跳转到<code>list.jsp</code></td>
</tr>
<tr>
<td><code>/stu/add.jsp</code></td>
<td>添加学生，成功后跳转到<code>list.jsp</code></td>
</tr>
<tr>
<td><code>/stu/update_view.jsp</code></td>
<td>修改学生页面，成功后跳转到<code>list.jsp</code></td>
</tr>
<tr>
<td><code>/stu/delete.jsp</code></td>
<td>删除学生，成功后跳转到<code>list.jsp</code></td>
</tr>
<tr>
<td><code>/stu/update.jsp</code></td>
<td>修改学生，成功后跳转到<code>list.jsp</code></td>
</tr>
<tr>
<td><code>/stu/init.jsp</code></td>
<td>初始化学生列表，成功后跳转到<code>list.jsp</code></td>
</tr>
<tr>
<td><code>/stu/list.jsp</code></td>
<td>以表格显示学生列表，每行包含修改、删除链接</td>
</tr>
</tbody>
</table>
<blockquote>
<p>主入口为：<code>/stu/init.jsp</code></p>
</blockquote>
<ol>
<li>
<p>创建模型类<code>java/stu/Sutudent.java</code>封装学生信息，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/java/stu/Student.java</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-11-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-11-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-11-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-11-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-11-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-11-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-11-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-11-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-11-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-11-10">10</a></span>
<span class="normal"><a href="#__codelineno-11-11">11</a></span>
<span class="normal"><a href="#__codelineno-11-12">12</a></span>
<span class="normal"><a href="#__codelineno-11-13">13</a></span>
<span class="normal"><a href="#__codelineno-11-14">14</a></span>
<span class="normal"><a href="#__codelineno-11-15">15</a></span>
<span class="normal"><a href="#__codelineno-11-16">16</a></span>
<span class="normal"><a href="#__codelineno-11-17">17</a></span>
<span class="normal"><a href="#__codelineno-11-18">18</a></span>
<span class="normal"><a href="#__codelineno-11-19">19</a></span>
<span class="normal"><a href="#__codelineno-11-20">20</a></span>
<span class="normal"><a href="#__codelineno-11-21">21</a></span>
<span class="normal"><a href="#__codelineno-11-22">22</a></span>
<span class="normal"><a href="#__codelineno-11-23">23</a></span>
<span class="normal"><a href="#__codelineno-11-24">24</a></span>
<span class="normal"><a href="#__codelineno-11-25">25</a></span>
<span class="normal"><a href="#__codelineno-11-26">26</a></span>
<span class="normal"><a href="#__codelineno-11-27">27</a></span>
<span class="normal"><a href="#__codelineno-11-28">28</a></span>
<span class="normal"><a href="#__codelineno-11-29">29</a></span>
<span class="normal"><a href="#__codelineno-11-30">30</a></span>
<span class="normal"><a href="#__codelineno-11-31">31</a></span>
<span class="normal"><a href="#__codelineno-11-32">32</a></span>
<span class="normal"><a href="#__codelineno-11-33">33</a></span>
<span class="normal"><a href="#__codelineno-11-34">34</a></span>
<span class="normal"><a href="#__codelineno-11-35">35</a></span>
<span class="normal"><a href="#__codelineno-11-36">36</a></span>
<span class="normal"><a href="#__codelineno-11-37">37</a></span>
<span class="normal"><a href="#__codelineno-11-38">38</a></span>
<span class="normal"><a href="#__codelineno-11-39">39</a></span>
<span class="normal"><a href="#__codelineno-11-40">40</a></span>
<span class="normal"><a href="#__codelineno-11-41">41</a></span>
<span class="normal"><a href="#__codelineno-11-42">42</a></span>
<span class="normal"><a href="#__codelineno-11-43">43</a></span>
<span class="normal"><a href="#__codelineno-11-44">44</a></span>
<span class="normal"><a href="#__codelineno-11-45">45</a></span>
<span class="normal"><a href="#__codelineno-11-46">46</a></span>
<span class="normal"><a href="#__codelineno-11-47">47</a></span>
<span class="normal"><a href="#__codelineno-11-48">48</a></span>
<span class="normal"><a href="#__codelineno-11-49">49</a></span>
<span class="normal"><a href="#__codelineno-11-50">50</a></span>
<span class="normal"><a href="#__codelineno-11-51">51</a></span>
<span class="normal"><a href="#__codelineno-11-52">52</a></span>
<span class="normal"><a href="#__codelineno-11-53">53</a></span>
<span class="normal"><a href="#__codelineno-11-54">54</a></span>
<span class="normal"><a href="#__codelineno-11-55">55</a></span>
<span class="normal"><a href="#__codelineno-11-56">56</a></span>
<span class="normal"><a href="#__codelineno-11-57">57</a></span>
<span class="normal"><a href="#__codelineno-11-58">58</a></span>
<span class="normal"><a href="#__codelineno-11-59">59</a></span>
<span class="normal"><a href="#__codelineno-11-60">60</a></span>
<span class="normal"><a href="#__codelineno-11-61">61</a></span>
<span class="normal"><a href="#__codelineno-11-62">62</a></span>
<span class="normal"><a href="#__codelineno-11-63">63</a></span>
<span class="normal"><a href="#__codelineno-11-64">64</a></span>
<span class="normal"><a href="#__codelineno-11-65">65</a></span>
<span class="normal"><a href="#__codelineno-11-66">66</a></span>
<span class="normal"><a href="#__codelineno-11-67">67</a></span>
<span class="normal"><a href="#__codelineno-11-68">68</a></span>
<span class="normal"><a href="#__codelineno-11-69">69</a></span>
<span class="normal"><a href="#__codelineno-11-70">70</a></span>
<span class="normal"><a href="#__codelineno-11-71">71</a></span>
<span class="normal"><a href="#__codelineno-11-72">72</a></span>
<span class="normal"><a href="#__codelineno-11-73">73</a></span>
<span class="normal"><a href="#__codelineno-11-74">74</a></span>
<span class="normal"><a href="#__codelineno-11-75">75</a></span>
<span class="normal"><a href="#__codelineno-11-76">76</a></span>
<span class="normal"><a href="#__codelineno-11-77">77</a></span>
<span class="normal"><a href="#__codelineno-11-78">78</a></span>
<span class="normal"><a href="#__codelineno-11-79">79</a></span>
<span class="normal"><a href="#__codelineno-11-80">80</a></span>
<span class="normal"><a href="#__codelineno-11-81">81</a></span>
<span class="normal"><a href="#__codelineno-11-82">82</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-11-1" name="__codelineno-11-1"></a><span class="kn">package</span><span class="w"> </span><span class="nn">stu</span><span class="p">;</span>
<a id="__codelineno-11-2" name="__codelineno-11-2"></a>
<a id="__codelineno-11-3" name="__codelineno-11-3"></a><span class="cm">/**</span>
<a id="__codelineno-11-4" name="__codelineno-11-4"></a><span class="cm"> * Class Student</span>
<a id="__codelineno-11-5" name="__codelineno-11-5"></a><span class="cm"> * 学生表</span>
<a id="__codelineno-11-6" name="__codelineno-11-6"></a><span class="cm"> * @author XUST</span>
<a id="__codelineno-11-7" name="__codelineno-11-7"></a><span class="cm"> * @version 1.0, 2023-04-20</span>
<a id="__codelineno-11-8" name="__codelineno-11-8"></a><span class="cm"> */</span>
<a id="__codelineno-11-9" name="__codelineno-11-9"></a><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Student</span><span class="p">{</span>
<a id="__codelineno-11-10" name="__codelineno-11-10"></a><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="nf">Student</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-11-11" name="__codelineno-11-11"></a>
<a id="__codelineno-11-12" name="__codelineno-11-12"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-11-13" name="__codelineno-11-13"></a>
<a id="__codelineno-11-14" name="__codelineno-11-14"></a><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="nf">Student</span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">no</span><span class="p">,</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">name</span><span class="p">,</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">gender</span><span class="p">,</span><span class="w"> </span><span class="n">Integer</span><span class="w"> </span><span class="n">age</span><span class="p">,</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">dept</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-11-15" name="__codelineno-11-15"></a><span class="w">        </span><span class="k">this</span><span class="p">.</span><span class="na">no</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">no</span><span class="p">;</span>
<a id="__codelineno-11-16" name="__codelineno-11-16"></a><span class="w">        </span><span class="k">this</span><span class="p">.</span><span class="na">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">name</span><span class="p">;</span>
<a id="__codelineno-11-17" name="__codelineno-11-17"></a><span class="w">        </span><span class="k">this</span><span class="p">.</span><span class="na">gender</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">gender</span><span class="p">;</span>
<a id="__codelineno-11-18" name="__codelineno-11-18"></a><span class="w">        </span><span class="k">this</span><span class="p">.</span><span class="na">age</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">age</span><span class="p">;</span>
<a id="__codelineno-11-19" name="__codelineno-11-19"></a><span class="w">        </span><span class="k">this</span><span class="p">.</span><span class="na">dept</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dept</span><span class="p">;</span>
<a id="__codelineno-11-20" name="__codelineno-11-20"></a><span class="w">    </span><span class="p">}</span><span class="w">   </span>
<a id="__codelineno-11-21" name="__codelineno-11-21"></a>
<a id="__codelineno-11-22" name="__codelineno-11-22"></a><span class="w">    </span><span class="cm">/**</span>
<a id="__codelineno-11-23" name="__codelineno-11-23"></a><span class="cm">     * 学号</span>
<a id="__codelineno-11-24" name="__codelineno-11-24"></a><span class="cm">     */</span>
<a id="__codelineno-11-25" name="__codelineno-11-25"></a><span class="w">    </span><span class="kd">private</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">no</span><span class="p">;</span>
<a id="__codelineno-11-26" name="__codelineno-11-26"></a><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="nf">getNo</span><span class="p">(){</span>
<a id="__codelineno-11-27" name="__codelineno-11-27"></a><span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="n">no</span><span class="p">;</span>
<a id="__codelineno-11-28" name="__codelineno-11-28"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-11-29" name="__codelineno-11-29"></a>
<a id="__codelineno-11-30" name="__codelineno-11-30"></a><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">setNo</span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">newValue</span><span class="p">){</span>
<a id="__codelineno-11-31" name="__codelineno-11-31"></a><span class="w">        </span><span class="n">no</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">newValue</span><span class="p">;</span>
<a id="__codelineno-11-32" name="__codelineno-11-32"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-11-33" name="__codelineno-11-33"></a><span class="w">    </span><span class="cm">/**</span>
<a id="__codelineno-11-34" name="__codelineno-11-34"></a><span class="cm">     * 姓名</span>
<a id="__codelineno-11-35" name="__codelineno-11-35"></a><span class="cm">     */</span>
<a id="__codelineno-11-36" name="__codelineno-11-36"></a><span class="w">    </span><span class="kd">private</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">name</span><span class="p">;</span>
<a id="__codelineno-11-37" name="__codelineno-11-37"></a><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="nf">getName</span><span class="p">(){</span>
<a id="__codelineno-11-38" name="__codelineno-11-38"></a><span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="n">name</span><span class="p">;</span>
<a id="__codelineno-11-39" name="__codelineno-11-39"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-11-40" name="__codelineno-11-40"></a>
<a id="__codelineno-11-41" name="__codelineno-11-41"></a><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">setName</span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">newValue</span><span class="p">){</span>
<a id="__codelineno-11-42" name="__codelineno-11-42"></a><span class="w">        </span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">newValue</span><span class="p">;</span>
<a id="__codelineno-11-43" name="__codelineno-11-43"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-11-44" name="__codelineno-11-44"></a><span class="w">    </span><span class="cm">/**</span>
<a id="__codelineno-11-45" name="__codelineno-11-45"></a><span class="cm">     * 性别</span>
<a id="__codelineno-11-46" name="__codelineno-11-46"></a><span class="cm">     */</span>
<a id="__codelineno-11-47" name="__codelineno-11-47"></a><span class="w">    </span><span class="kd">private</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">gender</span><span class="p">;</span>
<a id="__codelineno-11-48" name="__codelineno-11-48"></a><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="nf">getGender</span><span class="p">(){</span>
<a id="__codelineno-11-49" name="__codelineno-11-49"></a><span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="n">gender</span><span class="p">;</span>
<a id="__codelineno-11-50" name="__codelineno-11-50"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-11-51" name="__codelineno-11-51"></a>
<a id="__codelineno-11-52" name="__codelineno-11-52"></a><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">setGender</span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">newValue</span><span class="p">){</span>
<a id="__codelineno-11-53" name="__codelineno-11-53"></a><span class="w">        </span><span class="n">gender</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">newValue</span><span class="p">;</span>
<a id="__codelineno-11-54" name="__codelineno-11-54"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-11-55" name="__codelineno-11-55"></a><span class="w">    </span><span class="cm">/**</span>
<a id="__codelineno-11-56" name="__codelineno-11-56"></a><span class="cm">     * 年龄</span>
<a id="__codelineno-11-57" name="__codelineno-11-57"></a><span class="cm">     */</span>
<a id="__codelineno-11-58" name="__codelineno-11-58"></a><span class="w">    </span><span class="kd">private</span><span class="w"> </span><span class="n">Integer</span><span class="w"> </span><span class="n">age</span><span class="p">;</span>
<a id="__codelineno-11-59" name="__codelineno-11-59"></a><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">Integer</span><span class="w"> </span><span class="nf">getAge</span><span class="p">(){</span>
<a id="__codelineno-11-60" name="__codelineno-11-60"></a><span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="n">age</span><span class="p">;</span>
<a id="__codelineno-11-61" name="__codelineno-11-61"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-11-62" name="__codelineno-11-62"></a>
<a id="__codelineno-11-63" name="__codelineno-11-63"></a><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">setAge</span><span class="p">(</span><span class="n">Integer</span><span class="w"> </span><span class="n">newValue</span><span class="p">){</span>
<a id="__codelineno-11-64" name="__codelineno-11-64"></a><span class="w">        </span><span class="n">age</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">newValue</span><span class="p">;</span>
<a id="__codelineno-11-65" name="__codelineno-11-65"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-11-66" name="__codelineno-11-66"></a><span class="w">    </span><span class="cm">/**</span>
<a id="__codelineno-11-67" name="__codelineno-11-67"></a><span class="cm">     * 所在系</span>
<a id="__codelineno-11-68" name="__codelineno-11-68"></a><span class="cm">     */</span>
<a id="__codelineno-11-69" name="__codelineno-11-69"></a><span class="w">    </span><span class="kd">private</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">dept</span><span class="p">;</span>
<a id="__codelineno-11-70" name="__codelineno-11-70"></a><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="nf">getDept</span><span class="p">(){</span>
<a id="__codelineno-11-71" name="__codelineno-11-71"></a><span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="n">dept</span><span class="p">;</span>
<a id="__codelineno-11-72" name="__codelineno-11-72"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-11-73" name="__codelineno-11-73"></a>
<a id="__codelineno-11-74" name="__codelineno-11-74"></a><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">setDept</span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">newValue</span><span class="p">){</span>
<a id="__codelineno-11-75" name="__codelineno-11-75"></a><span class="w">        </span><span class="n">dept</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">newValue</span><span class="p">;</span>
<a id="__codelineno-11-76" name="__codelineno-11-76"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-11-77" name="__codelineno-11-77"></a>
<a id="__codelineno-11-78" name="__codelineno-11-78"></a><span class="w">    </span><span class="nd">@Override</span>
<a id="__codelineno-11-79" name="__codelineno-11-79"></a><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="nf">toString</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-11-80" name="__codelineno-11-80"></a><span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="s">&quot;{&quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;\&quot;no\&quot;: &quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;\&quot;&quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">no</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;\&quot;&quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;, &quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;\&quot;name\&quot;: &quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;\&quot;&quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;\&quot;&quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;, &quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;\&quot;gender\&quot;: &quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;\&quot;&quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">gender</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;\&quot;&quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;, &quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;\&quot;age\&quot;: &quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">age</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;, &quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;\&quot;dept\&quot;: &quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;\&quot;&quot;</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">dept</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">&quot;\&quot;&quot;</span><span class="w"> </span><span class="o">+</span><span class="w">  </span><span class="s">&quot;}&quot;</span><span class="p">;</span>
<a id="__codelineno-11-81" name="__codelineno-11-81"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-11-82" name="__codelineno-11-82"></a><span class="p">}</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建初始化页面<code>webapp/stu/init.jsp</code>初始化学生列表，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/stu/init.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-12-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-12-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-12-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-12-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-12-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-12-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-12-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-12-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-12-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-12-10">10</a></span>
<span class="normal"><a href="#__codelineno-12-11">11</a></span>
<span class="normal"><a href="#__codelineno-12-12">12</a></span>
<span class="normal"><a href="#__codelineno-12-13">13</a></span>
<span class="normal"><a href="#__codelineno-12-14">14</a></span>
<span class="normal"><a href="#__codelineno-12-15">15</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;stu.Student&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-12-2" name="__codelineno-12-2"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;java.util.ArrayList&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-12-3" name="__codelineno-12-3"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;java.util.List&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-12-4" name="__codelineno-12-4"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">contentType</span><span class="o">=</span><span class="s">&quot;text/html;charset=utf-8&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-12-5" name="__codelineno-12-5"></a><span class="k">&lt;%</span>
<a id="__codelineno-12-6" name="__codelineno-12-6"></a><span class="w">  </span><span class="n">List</span><span class="o">&lt;</span><span class="n">Student</span><span class="o">&gt;</span><span class="w"> </span><span class="n">students</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">ArrayList</span><span class="o">&lt;</span><span class="n">Student</span><span class="o">&gt;</span><span class="p">();</span>
<a id="__codelineno-12-7" name="__codelineno-12-7"></a><span class="w">  </span><span class="n">students</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">Student</span><span class="p">(</span><span class="s">&quot;1&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;张三&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;男&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">20</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;计科&quot;</span><span class="p">));</span>
<a id="__codelineno-12-8" name="__codelineno-12-8"></a><span class="w">  </span><span class="n">students</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">Student</span><span class="p">(</span><span class="s">&quot;2&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;李四&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;男&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">20</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;软工&quot;</span><span class="p">));</span>
<a id="__codelineno-12-9" name="__codelineno-12-9"></a><span class="w">  </span><span class="n">students</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">Student</span><span class="p">(</span><span class="s">&quot;3&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;王五&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;男&quot;</span><span class="p">,</span><span class="w"> </span><span class="mi">20</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;网工&quot;</span><span class="p">));</span>
<a id="__codelineno-12-10" name="__codelineno-12-10"></a>
<a id="__codelineno-12-11" name="__codelineno-12-11"></a><span class="w">  </span><span class="n">session</span><span class="p">.</span><span class="na">setAttribute</span><span class="p">(</span><span class="s">&quot;stu_list&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">students</span><span class="p">);</span>
<a id="__codelineno-12-12" name="__codelineno-12-12"></a>
<a id="__codelineno-12-13" name="__codelineno-12-13"></a><span class="w">  </span><span class="c1">//初始化完成，回到列表</span>
<a id="__codelineno-12-14" name="__codelineno-12-14"></a><span class="w">  </span><span class="n">response</span><span class="p">.</span><span class="na">sendRedirect</span><span class="p">(</span><span class="n">String</span><span class="p">.</span><span class="na">format</span><span class="p">(</span><span class="s">&quot;%s%s&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">request</span><span class="p">.</span><span class="na">getContextPath</span><span class="p">(),</span><span class="w"> </span><span class="s">&quot;/stu/list.jsp&quot;</span><span class="p">));</span>
<a id="__codelineno-12-15" name="__codelineno-12-15"></a><span class="k">%&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建列表页面<code>webapp/stu/list.jsp</code>显示学生列表，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/stu/list.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-13-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-13-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-13-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-13-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-13-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-13-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-13-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-13-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-13-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-13-10">10</a></span>
<span class="normal"><a href="#__codelineno-13-11">11</a></span>
<span class="normal"><a href="#__codelineno-13-12">12</a></span>
<span class="normal"><a href="#__codelineno-13-13">13</a></span>
<span class="normal"><a href="#__codelineno-13-14">14</a></span>
<span class="normal"><a href="#__codelineno-13-15">15</a></span>
<span class="normal"><a href="#__codelineno-13-16">16</a></span>
<span class="normal"><a href="#__codelineno-13-17">17</a></span>
<span class="normal"><a href="#__codelineno-13-18">18</a></span>
<span class="normal"><a href="#__codelineno-13-19">19</a></span>
<span class="normal"><a href="#__codelineno-13-20">20</a></span>
<span class="normal"><a href="#__codelineno-13-21">21</a></span>
<span class="normal"><a href="#__codelineno-13-22">22</a></span>
<span class="normal"><a href="#__codelineno-13-23">23</a></span>
<span class="normal"><a href="#__codelineno-13-24">24</a></span>
<span class="normal"><a href="#__codelineno-13-25">25</a></span>
<span class="normal"><a href="#__codelineno-13-26">26</a></span>
<span class="normal"><a href="#__codelineno-13-27">27</a></span>
<span class="normal"><a href="#__codelineno-13-28">28</a></span>
<span class="normal"><a href="#__codelineno-13-29">29</a></span>
<span class="normal"><a href="#__codelineno-13-30">30</a></span>
<span class="normal"><a href="#__codelineno-13-31">31</a></span>
<span class="normal"><a href="#__codelineno-13-32">32</a></span>
<span class="normal"><a href="#__codelineno-13-33">33</a></span>
<span class="normal"><a href="#__codelineno-13-34">34</a></span>
<span class="normal"><a href="#__codelineno-13-35">35</a></span>
<span class="normal"><a href="#__codelineno-13-36">36</a></span>
<span class="normal"><a href="#__codelineno-13-37">37</a></span>
<span class="normal"><a href="#__codelineno-13-38">38</a></span>
<span class="normal"><a href="#__codelineno-13-39">39</a></span>
<span class="normal"><a href="#__codelineno-13-40">40</a></span>
<span class="normal"><a href="#__codelineno-13-41">41</a></span>
<span class="normal"><a href="#__codelineno-13-42">42</a></span>
<span class="normal"><a href="#__codelineno-13-43">43</a></span>
<span class="normal"><a href="#__codelineno-13-44">44</a></span>
<span class="normal"><a href="#__codelineno-13-45">45</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-13-1" name="__codelineno-13-1"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;stu.Student&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-13-2" name="__codelineno-13-2"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;java.util.ArrayList&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-13-3" name="__codelineno-13-3"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;java.util.List&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-13-4" name="__codelineno-13-4"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">contentType</span><span class="o">=</span><span class="s">&quot;text/html;charset=utf-8&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-13-5" name="__codelineno-13-5"></a><span class="cp">&lt;!DOCTYPE html&gt;</span>
<a id="__codelineno-13-6" name="__codelineno-13-6"></a><span class="nt">&lt;html&gt;</span>
<a id="__codelineno-13-7" name="__codelineno-13-7"></a>
<a id="__codelineno-13-8" name="__codelineno-13-8"></a><span class="nt">&lt;head&gt;</span>
<a id="__codelineno-13-9" name="__codelineno-13-9"></a><span class="w">  </span><span class="nt">&lt;meta</span><span class="w"> </span><span class="na">charset=</span><span class="s">&quot;utf-8&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-13-10" name="__codelineno-13-10"></a><span class="w">  </span><span class="nt">&lt;title&gt;</span>学生表<span class="nt">&lt;/title&gt;</span>
<a id="__codelineno-13-11" name="__codelineno-13-11"></a><span class="nt">&lt;/head&gt;</span>
<a id="__codelineno-13-12" name="__codelineno-13-12"></a>
<a id="__codelineno-13-13" name="__codelineno-13-13"></a><span class="nt">&lt;body&gt;</span>
<a id="__codelineno-13-14" name="__codelineno-13-14"></a><span class="w">  </span><span class="nt">&lt;h3&gt;</span>学生表<span class="nt">&lt;/h3&gt;</span>
<a id="__codelineno-13-15" name="__codelineno-13-15"></a><span class="w">  </span><span class="nt">&lt;a</span><span class="w"> </span><span class="na">href=</span><span class="s">&quot;</span><span class="k">&lt;%=</span><span class="n">request</span><span class="p">.</span><span class="na">getContextPath</span><span class="p">()</span><span class="k">%&gt;</span><span class="s">/stu/add_view.jsp&quot;</span><span class="nt">&gt;</span>新增<span class="nt">&lt;/a&gt;</span>
<a id="__codelineno-13-16" name="__codelineno-13-16"></a><span class="w">  </span><span class="nt">&lt;table</span><span class="w"> </span><span class="na">id=</span><span class="s">&quot;STUDENT&quot;</span><span class="w"> </span><span class="na">border=</span><span class="s">&quot;1&quot;</span><span class="w"> </span><span class="na">width=</span><span class="s">&quot;100%&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-13-17" name="__codelineno-13-17"></a><span class="w">    </span><span class="nt">&lt;thead&gt;</span>
<a id="__codelineno-13-18" name="__codelineno-13-18"></a><span class="w">      </span><span class="nt">&lt;th&gt;</span>学号<span class="nt">&lt;/th&gt;</span>
<a id="__codelineno-13-19" name="__codelineno-13-19"></a><span class="w">      </span><span class="nt">&lt;th&gt;</span>姓名<span class="nt">&lt;/th&gt;</span>
<a id="__codelineno-13-20" name="__codelineno-13-20"></a><span class="w">      </span><span class="nt">&lt;th&gt;</span>性别<span class="nt">&lt;/th&gt;</span>
<a id="__codelineno-13-21" name="__codelineno-13-21"></a><span class="w">      </span><span class="nt">&lt;th&gt;</span>年龄<span class="nt">&lt;/th&gt;</span>
<a id="__codelineno-13-22" name="__codelineno-13-22"></a><span class="w">      </span><span class="nt">&lt;th&gt;</span>所在系<span class="nt">&lt;/th&gt;</span>
<a id="__codelineno-13-23" name="__codelineno-13-23"></a><span class="w">      </span><span class="nt">&lt;th&gt;</span>操作<span class="nt">&lt;/th&gt;</span>
<a id="__codelineno-13-24" name="__codelineno-13-24"></a><span class="w">    </span><span class="nt">&lt;/thead&gt;</span>
<a id="__codelineno-13-25" name="__codelineno-13-25"></a><span class="w">    </span><span class="nt">&lt;tbody&gt;</span>
<a id="__codelineno-13-26" name="__codelineno-13-26"></a><span class="w">        </span><span class="k">&lt;%</span>
<a id="__codelineno-13-27" name="__codelineno-13-27"></a><span class="w">                </span><span class="n">List</span><span class="o">&lt;</span><span class="n">Student</span><span class="o">&gt;</span><span class="w"> </span><span class="n">students</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">List</span><span class="o">&lt;</span><span class="n">Student</span><span class="o">&gt;</span><span class="p">)</span><span class="n">session</span><span class="p">.</span><span class="na">getAttribute</span><span class="p">(</span><span class="s">&quot;stu_list&quot;</span><span class="p">);</span>
<a id="__codelineno-13-28" name="__codelineno-13-28"></a><span class="w">        </span><span class="k">if</span><span class="p">(</span><span class="n">students</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">null</span><span class="p">){</span>
<a id="__codelineno-13-29" name="__codelineno-13-29"></a><span class="w">            </span><span class="k">for</span><span class="p">(</span><span class="n">Student</span><span class="w"> </span><span class="n">stu</span><span class="p">:</span><span class="w"> </span><span class="n">students</span><span class="p">){</span>
<a id="__codelineno-13-30" name="__codelineno-13-30"></a><span class="w">                </span><span class="n">String</span><span class="w"> </span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;&quot;</span><span class="p">;</span>
<a id="__codelineno-13-31" name="__codelineno-13-31"></a><span class="w">                </span><span class="n">line</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">String</span><span class="p">.</span><span class="na">format</span><span class="p">(</span><span class="s">&quot;&lt;td&gt;%s&lt;/td&gt;&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">stu</span><span class="p">.</span><span class="na">getNo</span><span class="p">());</span>
<a id="__codelineno-13-32" name="__codelineno-13-32"></a><span class="w">                </span><span class="n">line</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">String</span><span class="p">.</span><span class="na">format</span><span class="p">(</span><span class="s">&quot;&lt;td&gt;%s&lt;/td&gt;&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">stu</span><span class="p">.</span><span class="na">getName</span><span class="p">());</span>
<a id="__codelineno-13-33" name="__codelineno-13-33"></a><span class="w">                </span><span class="n">line</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">String</span><span class="p">.</span><span class="na">format</span><span class="p">(</span><span class="s">&quot;&lt;td&gt;%s&lt;/td&gt;&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">stu</span><span class="p">.</span><span class="na">getGender</span><span class="p">());</span>
<a id="__codelineno-13-34" name="__codelineno-13-34"></a><span class="w">                </span><span class="n">line</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">String</span><span class="p">.</span><span class="na">format</span><span class="p">(</span><span class="s">&quot;&lt;td&gt;%s&lt;/td&gt;&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">stu</span><span class="p">.</span><span class="na">getAge</span><span class="p">());</span>
<a id="__codelineno-13-35" name="__codelineno-13-35"></a><span class="w">                </span><span class="n">line</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">String</span><span class="p">.</span><span class="na">format</span><span class="p">(</span><span class="s">&quot;&lt;td&gt;%s&lt;/td&gt;&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">stu</span><span class="p">.</span><span class="na">getDept</span><span class="p">());</span>
<a id="__codelineno-13-36" name="__codelineno-13-36"></a><span class="w">                </span><span class="n">line</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">String</span><span class="p">.</span><span class="na">format</span><span class="p">(</span><span class="s">&quot;&lt;td&gt;&lt;a href=&#39;%s/stu/update_view.jsp?no=%s&#39;&gt;修改&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href=&#39;%s/stu/delete.jsp?no=%s&#39;&gt;删除&lt;/a&gt;&lt;/td&gt;&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">request</span><span class="p">.</span><span class="na">getContextPath</span><span class="p">(),</span><span class="w"> </span><span class="n">stu</span><span class="p">.</span><span class="na">getNo</span><span class="p">(),</span><span class="w"> </span><span class="n">request</span><span class="p">.</span><span class="na">getContextPath</span><span class="p">(),</span><span class="w"> </span><span class="n">stu</span><span class="p">.</span><span class="na">getNo</span><span class="p">());</span>
<a id="__codelineno-13-37" name="__codelineno-13-37"></a><span class="w">              </span><span class="n">out</span><span class="p">.</span><span class="na">print</span><span class="p">(</span><span class="n">String</span><span class="p">.</span><span class="na">format</span><span class="p">(</span><span class="s">&quot;&lt;tr&gt;%s&lt;/tr&gt;&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="p">));</span><span class="w">            </span>
<a id="__codelineno-13-38" name="__codelineno-13-38"></a><span class="w">            </span><span class="p">}</span>
<a id="__codelineno-13-39" name="__codelineno-13-39"></a><span class="w">        </span><span class="p">}</span>
<a id="__codelineno-13-40" name="__codelineno-13-40"></a><span class="w">        </span><span class="k">%&gt;</span>
<a id="__codelineno-13-41" name="__codelineno-13-41"></a><span class="w">    </span><span class="nt">&lt;/tbody&gt;</span>
<a id="__codelineno-13-42" name="__codelineno-13-42"></a><span class="w">  </span><span class="nt">&lt;/table&gt;</span>
<a id="__codelineno-13-43" name="__codelineno-13-43"></a><span class="nt">&lt;/body&gt;</span>
<a id="__codelineno-13-44" name="__codelineno-13-44"></a>
<a id="__codelineno-13-45" name="__codelineno-13-45"></a><span class="nt">&lt;/html&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建新建界面页面<code>webapp/stu/add_view.jsp</code>用于添加界面，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/stu/add_view.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-14-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-14-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-14-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-14-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-14-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-14-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-14-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-14-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-14-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-14-10">10</a></span>
<span class="normal"><a href="#__codelineno-14-11">11</a></span>
<span class="normal"><a href="#__codelineno-14-12">12</a></span>
<span class="normal"><a href="#__codelineno-14-13">13</a></span>
<span class="normal"><a href="#__codelineno-14-14">14</a></span>
<span class="normal"><a href="#__codelineno-14-15">15</a></span>
<span class="normal"><a href="#__codelineno-14-16">16</a></span>
<span class="normal"><a href="#__codelineno-14-17">17</a></span>
<span class="normal"><a href="#__codelineno-14-18">18</a></span>
<span class="normal"><a href="#__codelineno-14-19">19</a></span>
<span class="normal"><a href="#__codelineno-14-20">20</a></span>
<span class="normal"><a href="#__codelineno-14-21">21</a></span>
<span class="normal"><a href="#__codelineno-14-22">22</a></span>
<span class="normal"><a href="#__codelineno-14-23">23</a></span>
<span class="normal"><a href="#__codelineno-14-24">24</a></span>
<span class="normal"><a href="#__codelineno-14-25">25</a></span>
<span class="normal"><a href="#__codelineno-14-26">26</a></span>
<span class="normal"><a href="#__codelineno-14-27">27</a></span>
<span class="normal"><a href="#__codelineno-14-28">28</a></span>
<span class="normal"><a href="#__codelineno-14-29">29</a></span>
<span class="normal"><a href="#__codelineno-14-30">30</a></span>
<span class="normal"><a href="#__codelineno-14-31">31</a></span>
<span class="normal"><a href="#__codelineno-14-32">32</a></span>
<span class="normal"><a href="#__codelineno-14-33">33</a></span>
<span class="normal"><a href="#__codelineno-14-34">34</a></span>
<span class="normal"><a href="#__codelineno-14-35">35</a></span>
<span class="normal"><a href="#__codelineno-14-36">36</a></span>
<span class="normal"><a href="#__codelineno-14-37">37</a></span>
<span class="normal"><a href="#__codelineno-14-38">38</a></span>
<span class="normal"><a href="#__codelineno-14-39">39</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-14-1" name="__codelineno-14-1"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">contentType</span><span class="o">=</span><span class="s">&quot;text/html;charset=utf-8&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-14-2" name="__codelineno-14-2"></a><span class="cp">&lt;!DOCTYPE html&gt;</span>
<a id="__codelineno-14-3" name="__codelineno-14-3"></a><span class="nt">&lt;html&gt;</span>
<a id="__codelineno-14-4" name="__codelineno-14-4"></a>
<a id="__codelineno-14-5" name="__codelineno-14-5"></a><span class="nt">&lt;head&gt;</span>
<a id="__codelineno-14-6" name="__codelineno-14-6"></a><span class="w">  </span><span class="nt">&lt;meta</span><span class="w"> </span><span class="na">charset=</span><span class="s">&quot;utf-8&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-14-7" name="__codelineno-14-7"></a><span class="w">  </span><span class="nt">&lt;title&gt;</span>学生表<span class="nt">&lt;/title&gt;</span>
<a id="__codelineno-14-8" name="__codelineno-14-8"></a><span class="nt">&lt;/head&gt;</span>
<a id="__codelineno-14-9" name="__codelineno-14-9"></a>
<a id="__codelineno-14-10" name="__codelineno-14-10"></a><span class="nt">&lt;body&gt;</span>
<a id="__codelineno-14-11" name="__codelineno-14-11"></a><span class="w">  </span><span class="nt">&lt;h3&gt;</span>学生表<span class="nt">&lt;/h3&gt;</span>
<a id="__codelineno-14-12" name="__codelineno-14-12"></a><span class="w">  </span><span class="nt">&lt;div&gt;</span>
<a id="__codelineno-14-13" name="__codelineno-14-13"></a><span class="w">    </span><span class="nt">&lt;form</span><span class="w"> </span><span class="na">action=</span><span class="s">&quot;</span><span class="k">&lt;%=</span><span class="n">String</span><span class="p">.</span><span class="na">format</span><span class="p">(</span><span class="s">&quot;%s/stu/add.jsp&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">request</span><span class="p">.</span><span class="na">getContextPath</span><span class="p">())</span><span class="k">%&gt;</span><span class="s">&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-14-14" name="__codelineno-14-14"></a><span class="w">      </span><span class="nt">&lt;div&gt;</span>
<a id="__codelineno-14-15" name="__codelineno-14-15"></a><span class="w">        </span><span class="nt">&lt;label</span><span class="w"> </span><span class="na">for=</span><span class="s">&quot;no&quot;</span><span class="nt">&gt;</span>学号:<span class="nt">&lt;/label&gt;</span>
<a id="__codelineno-14-16" name="__codelineno-14-16"></a><span class="w">        </span><span class="nt">&lt;input</span><span class="w"> </span><span class="na">type=</span><span class="s">&quot;text&quot;</span><span class="w"> </span><span class="na">id=</span><span class="s">&quot;no&quot;</span><span class="w"> </span><span class="na">name=</span><span class="s">&quot;no&quot;</span><span class="w"> </span><span class="na">placeholder=</span><span class="s">&quot;请输入学号..&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-14-17" name="__codelineno-14-17"></a><span class="w">      </span><span class="nt">&lt;/div&gt;</span>
<a id="__codelineno-14-18" name="__codelineno-14-18"></a><span class="w">      </span><span class="nt">&lt;div&gt;</span>
<a id="__codelineno-14-19" name="__codelineno-14-19"></a><span class="w">        </span><span class="nt">&lt;label</span><span class="w"> </span><span class="na">for=</span><span class="s">&quot;name&quot;</span><span class="nt">&gt;</span>姓名:<span class="nt">&lt;/label&gt;</span>
<a id="__codelineno-14-20" name="__codelineno-14-20"></a><span class="w">        </span><span class="nt">&lt;input</span><span class="w"> </span><span class="na">type=</span><span class="s">&quot;text&quot;</span><span class="w"> </span><span class="na">id=</span><span class="s">&quot;name&quot;</span><span class="w"> </span><span class="na">name=</span><span class="s">&quot;name&quot;</span><span class="w"> </span><span class="na">placeholder=</span><span class="s">&quot;请输入姓名..&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-14-21" name="__codelineno-14-21"></a><span class="w">      </span><span class="nt">&lt;/div&gt;</span>
<a id="__codelineno-14-22" name="__codelineno-14-22"></a><span class="w">      </span><span class="nt">&lt;div&gt;</span>
<a id="__codelineno-14-23" name="__codelineno-14-23"></a><span class="w">        </span><span class="nt">&lt;label</span><span class="w"> </span><span class="na">for=</span><span class="s">&quot;gender&quot;</span><span class="nt">&gt;</span>性别:<span class="nt">&lt;/label&gt;</span>
<a id="__codelineno-14-24" name="__codelineno-14-24"></a><span class="w">        </span><span class="nt">&lt;input</span><span class="w"> </span><span class="na">type=</span><span class="s">&quot;text&quot;</span><span class="w"> </span><span class="na">id=</span><span class="s">&quot;gender&quot;</span><span class="w"> </span><span class="na">name=</span><span class="s">&quot;gender&quot;</span><span class="w"> </span><span class="na">placeholder=</span><span class="s">&quot;请输入性别..&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-14-25" name="__codelineno-14-25"></a><span class="w">      </span><span class="nt">&lt;/div&gt;</span>
<a id="__codelineno-14-26" name="__codelineno-14-26"></a><span class="w">      </span><span class="nt">&lt;div&gt;</span>
<a id="__codelineno-14-27" name="__codelineno-14-27"></a><span class="w">        </span><span class="nt">&lt;label</span><span class="w"> </span><span class="na">for=</span><span class="s">&quot;age&quot;</span><span class="nt">&gt;</span>年龄:<span class="nt">&lt;/label&gt;</span>
<a id="__codelineno-14-28" name="__codelineno-14-28"></a><span class="w">        </span><span class="nt">&lt;input</span><span class="w"> </span><span class="na">type=</span><span class="s">&quot;number&quot;</span><span class="w"> </span><span class="na">id=</span><span class="s">&quot;age&quot;</span><span class="w"> </span><span class="na">name=</span><span class="s">&quot;age&quot;</span><span class="w"> </span><span class="na">placeholder=</span><span class="s">&quot;请输入年龄..&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-14-29" name="__codelineno-14-29"></a><span class="w">      </span><span class="nt">&lt;/div&gt;</span>
<a id="__codelineno-14-30" name="__codelineno-14-30"></a><span class="w">      </span><span class="nt">&lt;div&gt;</span>
<a id="__codelineno-14-31" name="__codelineno-14-31"></a><span class="w">        </span><span class="nt">&lt;label</span><span class="w"> </span><span class="na">for=</span><span class="s">&quot;dept&quot;</span><span class="nt">&gt;</span>所在系:<span class="nt">&lt;/label&gt;</span>
<a id="__codelineno-14-32" name="__codelineno-14-32"></a><span class="w">        </span><span class="nt">&lt;input</span><span class="w"> </span><span class="na">type=</span><span class="s">&quot;text&quot;</span><span class="w"> </span><span class="na">id=</span><span class="s">&quot;dept&quot;</span><span class="w"> </span><span class="na">name=</span><span class="s">&quot;dept&quot;</span><span class="w"> </span><span class="na">placeholder=</span><span class="s">&quot;请输入所在系..&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-14-33" name="__codelineno-14-33"></a><span class="w">      </span><span class="nt">&lt;/div&gt;</span>
<a id="__codelineno-14-34" name="__codelineno-14-34"></a><span class="w">      </span><span class="nt">&lt;button</span><span class="w"> </span><span class="na">type=</span><span class="s">&quot;submit&quot;</span><span class="nt">&gt;</span>提交<span class="nt">&lt;/button&gt;</span>
<a id="__codelineno-14-35" name="__codelineno-14-35"></a><span class="w">    </span><span class="nt">&lt;/form&gt;</span>
<a id="__codelineno-14-36" name="__codelineno-14-36"></a><span class="w">  </span><span class="nt">&lt;/div&gt;</span>
<a id="__codelineno-14-37" name="__codelineno-14-37"></a><span class="nt">&lt;/body&gt;</span>
<a id="__codelineno-14-38" name="__codelineno-14-38"></a>
<a id="__codelineno-14-39" name="__codelineno-14-39"></a><span class="nt">&lt;/html&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建新建页面<code>webapp/stu/add.jsp</code>实现添加功能，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/stu/add.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-15-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-15-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-15-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-15-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-15-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-15-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-15-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-15-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-15-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-15-10">10</a></span>
<span class="normal"><a href="#__codelineno-15-11">11</a></span>
<span class="normal"><a href="#__codelineno-15-12">12</a></span>
<span class="normal"><a href="#__codelineno-15-13">13</a></span>
<span class="normal"><a href="#__codelineno-15-14">14</a></span>
<span class="normal"><a href="#__codelineno-15-15">15</a></span>
<span class="normal"><a href="#__codelineno-15-16">16</a></span>
<span class="normal"><a href="#__codelineno-15-17">17</a></span>
<span class="normal"><a href="#__codelineno-15-18">18</a></span>
<span class="normal"><a href="#__codelineno-15-19">19</a></span>
<span class="normal"><a href="#__codelineno-15-20">20</a></span>
<span class="normal"><a href="#__codelineno-15-21">21</a></span>
<span class="normal"><a href="#__codelineno-15-22">22</a></span>
<span class="normal"><a href="#__codelineno-15-23">23</a></span>
<span class="normal"><a href="#__codelineno-15-24">24</a></span>
<span class="normal"><a href="#__codelineno-15-25">25</a></span>
<span class="normal"><a href="#__codelineno-15-26">26</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-15-1" name="__codelineno-15-1"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;stu.Student&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-15-2" name="__codelineno-15-2"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;java.util.ArrayList&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-15-3" name="__codelineno-15-3"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;java.util.List&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-15-4" name="__codelineno-15-4"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">contentType</span><span class="o">=</span><span class="s">&quot;text/html;charset=utf-8&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-15-5" name="__codelineno-15-5"></a><span class="k">&lt;%</span>
<a id="__codelineno-15-6" name="__codelineno-15-6"></a><span class="w">  </span><span class="n">Student</span><span class="w"> </span><span class="n">stu_new</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Student</span><span class="p">();</span>
<a id="__codelineno-15-7" name="__codelineno-15-7"></a>
<a id="__codelineno-15-8" name="__codelineno-15-8"></a><span class="w">  </span><span class="c1">//获取表单数据</span>
<a id="__codelineno-15-9" name="__codelineno-15-9"></a><span class="w">  </span><span class="n">stu_new</span><span class="p">.</span><span class="na">setNo</span><span class="p">(</span><span class="n">request</span><span class="p">.</span><span class="na">getParameter</span><span class="p">(</span><span class="s">&quot;no&quot;</span><span class="p">));</span>
<a id="__codelineno-15-10" name="__codelineno-15-10"></a><span class="w">  </span><span class="n">stu_new</span><span class="p">.</span><span class="na">setName</span><span class="p">(</span><span class="n">request</span><span class="p">.</span><span class="na">getParameter</span><span class="p">(</span><span class="s">&quot;name&quot;</span><span class="p">));</span><span class="w"> </span>
<a id="__codelineno-15-11" name="__codelineno-15-11"></a><span class="w">  </span><span class="n">stu_new</span><span class="p">.</span><span class="na">setGender</span><span class="p">(</span><span class="n">request</span><span class="p">.</span><span class="na">getParameter</span><span class="p">(</span><span class="s">&quot;gender&quot;</span><span class="p">));</span><span class="w"> </span>
<a id="__codelineno-15-12" name="__codelineno-15-12"></a><span class="w">  </span><span class="k">try</span><span class="p">{</span>
<a id="__codelineno-15-13" name="__codelineno-15-13"></a><span class="w">    </span><span class="n">stu_new</span><span class="p">.</span><span class="na">setAge</span><span class="p">(</span><span class="n">Integer</span><span class="p">.</span><span class="na">parseInt</span><span class="p">(</span><span class="n">request</span><span class="p">.</span><span class="na">getParameter</span><span class="p">(</span><span class="s">&quot;age&quot;</span><span class="p">)));</span><span class="w"> </span>
<a id="__codelineno-15-14" name="__codelineno-15-14"></a><span class="w">  </span><span class="p">}</span><span class="k">catch</span><span class="p">(</span><span class="n">Exception</span><span class="w"> </span><span class="n">e</span><span class="p">){</span>
<a id="__codelineno-15-15" name="__codelineno-15-15"></a>
<a id="__codelineno-15-16" name="__codelineno-15-16"></a><span class="w">  </span><span class="p">}</span>
<a id="__codelineno-15-17" name="__codelineno-15-17"></a><span class="w">  </span><span class="n">stu_new</span><span class="p">.</span><span class="na">setDept</span><span class="p">(</span><span class="n">request</span><span class="p">.</span><span class="na">getParameter</span><span class="p">(</span><span class="s">&quot;dept&quot;</span><span class="p">));</span><span class="w"> </span>
<a id="__codelineno-15-18" name="__codelineno-15-18"></a>
<a id="__codelineno-15-19" name="__codelineno-15-19"></a><span class="w">  </span><span class="n">List</span><span class="o">&lt;</span><span class="n">Student</span><span class="o">&gt;</span><span class="w"> </span><span class="n">students</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">List</span><span class="o">&lt;</span><span class="n">Student</span><span class="o">&gt;</span><span class="p">)</span><span class="n">session</span><span class="p">.</span><span class="na">getAttribute</span><span class="p">(</span><span class="s">&quot;stu_list&quot;</span><span class="p">);</span>
<a id="__codelineno-15-20" name="__codelineno-15-20"></a><span class="w">  </span><span class="k">if</span><span class="p">(</span><span class="n">students</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">null</span><span class="p">){</span>
<a id="__codelineno-15-21" name="__codelineno-15-21"></a><span class="w">    </span><span class="n">students</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="n">stu_new</span><span class="p">);</span>
<a id="__codelineno-15-22" name="__codelineno-15-22"></a><span class="w">  </span><span class="p">}</span>
<a id="__codelineno-15-23" name="__codelineno-15-23"></a>
<a id="__codelineno-15-24" name="__codelineno-15-24"></a><span class="w">  </span><span class="c1">//操作完成，回到列表</span>
<a id="__codelineno-15-25" name="__codelineno-15-25"></a><span class="w">  </span><span class="n">response</span><span class="p">.</span><span class="na">sendRedirect</span><span class="p">(</span><span class="n">String</span><span class="p">.</span><span class="na">format</span><span class="p">(</span><span class="s">&quot;%s%s&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">request</span><span class="p">.</span><span class="na">getContextPath</span><span class="p">(),</span><span class="w"> </span><span class="s">&quot;/stu/list.jsp&quot;</span><span class="p">));</span>
<a id="__codelineno-15-26" name="__codelineno-15-26"></a><span class="k">%&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建修改界面页面<code>webapp/stu/update_view.jsp</code>用于修改界面，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/stu/update_view.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-16-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-16-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-16-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-16-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-16-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-16-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-16-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-16-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-16-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-16-10">10</a></span>
<span class="normal"><a href="#__codelineno-16-11">11</a></span>
<span class="normal"><a href="#__codelineno-16-12">12</a></span>
<span class="normal"><a href="#__codelineno-16-13">13</a></span>
<span class="normal"><a href="#__codelineno-16-14">14</a></span>
<span class="normal"><a href="#__codelineno-16-15">15</a></span>
<span class="normal"><a href="#__codelineno-16-16">16</a></span>
<span class="normal"><a href="#__codelineno-16-17">17</a></span>
<span class="normal"><a href="#__codelineno-16-18">18</a></span>
<span class="normal"><a href="#__codelineno-16-19">19</a></span>
<span class="normal"><a href="#__codelineno-16-20">20</a></span>
<span class="normal"><a href="#__codelineno-16-21">21</a></span>
<span class="normal"><a href="#__codelineno-16-22">22</a></span>
<span class="normal"><a href="#__codelineno-16-23">23</a></span>
<span class="normal"><a href="#__codelineno-16-24">24</a></span>
<span class="normal"><a href="#__codelineno-16-25">25</a></span>
<span class="normal"><a href="#__codelineno-16-26">26</a></span>
<span class="normal"><a href="#__codelineno-16-27">27</a></span>
<span class="normal"><a href="#__codelineno-16-28">28</a></span>
<span class="normal"><a href="#__codelineno-16-29">29</a></span>
<span class="normal"><a href="#__codelineno-16-30">30</a></span>
<span class="normal"><a href="#__codelineno-16-31">31</a></span>
<span class="normal"><a href="#__codelineno-16-32">32</a></span>
<span class="normal"><a href="#__codelineno-16-33">33</a></span>
<span class="normal"><a href="#__codelineno-16-34">34</a></span>
<span class="normal"><a href="#__codelineno-16-35">35</a></span>
<span class="normal"><a href="#__codelineno-16-36">36</a></span>
<span class="normal"><a href="#__codelineno-16-37">37</a></span>
<span class="normal"><a href="#__codelineno-16-38">38</a></span>
<span class="normal"><a href="#__codelineno-16-39">39</a></span>
<span class="normal"><a href="#__codelineno-16-40">40</a></span>
<span class="normal"><a href="#__codelineno-16-41">41</a></span>
<span class="normal"><a href="#__codelineno-16-42">42</a></span>
<span class="normal"><a href="#__codelineno-16-43">43</a></span>
<span class="normal"><a href="#__codelineno-16-44">44</a></span>
<span class="normal"><a href="#__codelineno-16-45">45</a></span>
<span class="normal"><a href="#__codelineno-16-46">46</a></span>
<span class="normal"><a href="#__codelineno-16-47">47</a></span>
<span class="normal"><a href="#__codelineno-16-48">48</a></span>
<span class="normal"><a href="#__codelineno-16-49">49</a></span>
<span class="normal"><a href="#__codelineno-16-50">50</a></span>
<span class="normal"><a href="#__codelineno-16-51">51</a></span>
<span class="normal"><a href="#__codelineno-16-52">52</a></span>
<span class="normal"><a href="#__codelineno-16-53">53</a></span>
<span class="normal"><a href="#__codelineno-16-54">54</a></span>
<span class="normal"><a href="#__codelineno-16-55">55</a></span>
<span class="normal"><a href="#__codelineno-16-56">56</a></span>
<span class="normal"><a href="#__codelineno-16-57">57</a></span>
<span class="normal"><a href="#__codelineno-16-58">58</a></span>
<span class="normal"><a href="#__codelineno-16-59">59</a></span>
<span class="normal"><a href="#__codelineno-16-60">60</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-16-1" name="__codelineno-16-1"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;stu.Student&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-16-2" name="__codelineno-16-2"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;java.util.ArrayList&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-16-3" name="__codelineno-16-3"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;java.util.List&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-16-4" name="__codelineno-16-4"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">contentType</span><span class="o">=</span><span class="s">&quot;text/html;charset=utf-8&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-16-5" name="__codelineno-16-5"></a><span class="cp">&lt;!DOCTYPE html&gt;</span>
<a id="__codelineno-16-6" name="__codelineno-16-6"></a><span class="nt">&lt;html&gt;</span>
<a id="__codelineno-16-7" name="__codelineno-16-7"></a>
<a id="__codelineno-16-8" name="__codelineno-16-8"></a><span class="nt">&lt;head&gt;</span>
<a id="__codelineno-16-9" name="__codelineno-16-9"></a><span class="w">  </span><span class="nt">&lt;meta</span><span class="w"> </span><span class="na">charset=</span><span class="s">&quot;utf-8&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-16-10" name="__codelineno-16-10"></a><span class="w">  </span><span class="nt">&lt;title&gt;</span>学生表<span class="nt">&lt;/title&gt;</span>
<a id="__codelineno-16-11" name="__codelineno-16-11"></a><span class="nt">&lt;/head&gt;</span>
<a id="__codelineno-16-12" name="__codelineno-16-12"></a>
<a id="__codelineno-16-13" name="__codelineno-16-13"></a><span class="nt">&lt;body&gt;</span>
<a id="__codelineno-16-14" name="__codelineno-16-14"></a><span class="w">  </span><span class="nt">&lt;h3&gt;</span>学生表<span class="nt">&lt;/h3&gt;</span>
<a id="__codelineno-16-15" name="__codelineno-16-15"></a><span class="w">    </span><span class="k">&lt;%</span>
<a id="__codelineno-16-16" name="__codelineno-16-16"></a><span class="w">        </span><span class="n">String</span><span class="w"> </span><span class="n">no</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">request</span><span class="p">.</span><span class="na">getParameter</span><span class="p">(</span><span class="s">&quot;no&quot;</span><span class="p">);</span>
<a id="__codelineno-16-17" name="__codelineno-16-17"></a><span class="w">        </span><span class="n">Student</span><span class="w"> </span><span class="n">stu</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
<a id="__codelineno-16-18" name="__codelineno-16-18"></a><span class="w">        </span><span class="n">List</span><span class="o">&lt;</span><span class="n">Student</span><span class="o">&gt;</span><span class="w"> </span><span class="n">students</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">List</span><span class="o">&lt;</span><span class="n">Student</span><span class="o">&gt;</span><span class="p">)</span><span class="n">session</span><span class="p">.</span><span class="na">getAttribute</span><span class="p">(</span><span class="s">&quot;stu_list&quot;</span><span class="p">);</span>
<a id="__codelineno-16-19" name="__codelineno-16-19"></a><span class="w">        </span><span class="k">if</span><span class="p">(</span><span class="n">students</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">null</span><span class="p">){</span>
<a id="__codelineno-16-20" name="__codelineno-16-20"></a><span class="w">        </span><span class="kt">int</span><span class="w"> </span><span class="n">no_index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span><span class="p">;</span>
<a id="__codelineno-16-21" name="__codelineno-16-21"></a><span class="w">        </span><span class="k">for</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="n">students</span><span class="p">.</span><span class="na">size</span><span class="p">();</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
<a id="__codelineno-16-22" name="__codelineno-16-22"></a><span class="w">            </span><span class="k">if</span><span class="p">(</span><span class="n">no</span><span class="p">.</span><span class="na">equals</span><span class="p">(</span><span class="n">students</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">i</span><span class="p">).</span><span class="na">getNo</span><span class="p">())){</span>
<a id="__codelineno-16-23" name="__codelineno-16-23"></a><span class="w">                </span><span class="n">stu</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">students</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
<a id="__codelineno-16-24" name="__codelineno-16-24"></a><span class="w">                </span><span class="k">break</span><span class="p">;</span>
<a id="__codelineno-16-25" name="__codelineno-16-25"></a><span class="w">            </span><span class="p">}</span>
<a id="__codelineno-16-26" name="__codelineno-16-26"></a><span class="w">        </span><span class="p">}</span>
<a id="__codelineno-16-27" name="__codelineno-16-27"></a><span class="w">        </span><span class="p">}</span>
<a id="__codelineno-16-28" name="__codelineno-16-28"></a>
<a id="__codelineno-16-29" name="__codelineno-16-29"></a><span class="w">        </span><span class="k">if</span><span class="p">(</span><span class="n">stu</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="kc">null</span><span class="p">){</span>
<a id="__codelineno-16-30" name="__codelineno-16-30"></a><span class="w">            </span><span class="n">stu</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Student</span><span class="p">();</span>
<a id="__codelineno-16-31" name="__codelineno-16-31"></a><span class="w">        </span><span class="p">}</span>
<a id="__codelineno-16-32" name="__codelineno-16-32"></a><span class="w">    </span><span class="k">%&gt;</span>
<a id="__codelineno-16-33" name="__codelineno-16-33"></a><span class="w">  </span><span class="nt">&lt;div&gt;</span>
<a id="__codelineno-16-34" name="__codelineno-16-34"></a><span class="w">    </span><span class="nt">&lt;form</span><span class="w"> </span><span class="na">action=</span><span class="s">&quot;</span><span class="k">&lt;%=</span><span class="n">String</span><span class="p">.</span><span class="na">format</span><span class="p">(</span><span class="s">&quot;%s/stu/update.jsp&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">request</span><span class="p">.</span><span class="na">getContextPath</span><span class="p">())</span><span class="k">%&gt;</span><span class="s">&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-16-35" name="__codelineno-16-35"></a><span class="w">      </span><span class="nt">&lt;div&gt;</span>
<a id="__codelineno-16-36" name="__codelineno-16-36"></a><span class="w">        </span><span class="nt">&lt;label</span><span class="w"> </span><span class="na">for=</span><span class="s">&quot;no&quot;</span><span class="nt">&gt;</span>学号:<span class="nt">&lt;/label&gt;</span>
<a id="__codelineno-16-37" name="__codelineno-16-37"></a><span class="w">        </span><span class="nt">&lt;input</span><span class="w"> </span><span class="na">type=</span><span class="s">&quot;text&quot;</span><span class="w"> </span><span class="na">id=</span><span class="s">&quot;no&quot;</span><span class="w"> </span><span class="na">name=</span><span class="s">&quot;no&quot;</span><span class="w"> </span><span class="na">placeholder=</span><span class="s">&quot;请输入学号..&quot;</span><span class="w"> </span><span class="na">value=</span><span class="s">&quot;</span><span class="k">&lt;%=</span><span class="n">stu</span><span class="p">.</span><span class="na">getNo</span><span class="p">()</span><span class="k">%&gt;</span><span class="s">&quot;</span><span class="w"> </span><span class="na">readonly=</span><span class="s">&quot;true&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-16-38" name="__codelineno-16-38"></a><span class="w">      </span><span class="nt">&lt;/div&gt;</span>
<a id="__codelineno-16-39" name="__codelineno-16-39"></a><span class="w">      </span><span class="nt">&lt;div&gt;</span>
<a id="__codelineno-16-40" name="__codelineno-16-40"></a><span class="w">        </span><span class="nt">&lt;label</span><span class="w"> </span><span class="na">for=</span><span class="s">&quot;name&quot;</span><span class="nt">&gt;</span>姓名:<span class="nt">&lt;/label&gt;</span>
<a id="__codelineno-16-41" name="__codelineno-16-41"></a><span class="w">        </span><span class="nt">&lt;input</span><span class="w"> </span><span class="na">type=</span><span class="s">&quot;text&quot;</span><span class="w"> </span><span class="na">id=</span><span class="s">&quot;name&quot;</span><span class="w"> </span><span class="na">name=</span><span class="s">&quot;name&quot;</span><span class="w"> </span><span class="na">placeholder=</span><span class="s">&quot;请输入姓名..&quot;</span><span class="w"> </span><span class="na">value=</span><span class="s">&quot;</span><span class="k">&lt;%=</span><span class="n">stu</span><span class="p">.</span><span class="na">getName</span><span class="p">()</span><span class="k">%&gt;</span><span class="s">&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-16-42" name="__codelineno-16-42"></a><span class="w">      </span><span class="nt">&lt;/div&gt;</span>
<a id="__codelineno-16-43" name="__codelineno-16-43"></a><span class="w">      </span><span class="nt">&lt;div&gt;</span>
<a id="__codelineno-16-44" name="__codelineno-16-44"></a><span class="w">        </span><span class="nt">&lt;label</span><span class="w"> </span><span class="na">for=</span><span class="s">&quot;gender&quot;</span><span class="nt">&gt;</span>性别:<span class="nt">&lt;/label&gt;</span>
<a id="__codelineno-16-45" name="__codelineno-16-45"></a><span class="w">        </span><span class="nt">&lt;input</span><span class="w"> </span><span class="na">type=</span><span class="s">&quot;text&quot;</span><span class="w"> </span><span class="na">id=</span><span class="s">&quot;gender&quot;</span><span class="w"> </span><span class="na">name=</span><span class="s">&quot;gender&quot;</span><span class="w"> </span><span class="na">placeholder=</span><span class="s">&quot;请输入性别..&quot;</span><span class="w"> </span><span class="na">value=</span><span class="s">&quot;</span><span class="k">&lt;%=</span><span class="n">stu</span><span class="p">.</span><span class="na">getGender</span><span class="p">()</span><span class="k">%&gt;</span><span class="s">&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-16-46" name="__codelineno-16-46"></a><span class="w">      </span><span class="nt">&lt;/div&gt;</span>
<a id="__codelineno-16-47" name="__codelineno-16-47"></a><span class="w">      </span><span class="nt">&lt;div&gt;</span>
<a id="__codelineno-16-48" name="__codelineno-16-48"></a><span class="w">        </span><span class="nt">&lt;label</span><span class="w"> </span><span class="na">for=</span><span class="s">&quot;age&quot;</span><span class="nt">&gt;</span>年龄:<span class="nt">&lt;/label&gt;</span>
<a id="__codelineno-16-49" name="__codelineno-16-49"></a><span class="w">        </span><span class="nt">&lt;input</span><span class="w"> </span><span class="na">type=</span><span class="s">&quot;number&quot;</span><span class="w"> </span><span class="na">id=</span><span class="s">&quot;age&quot;</span><span class="w"> </span><span class="na">name=</span><span class="s">&quot;age&quot;</span><span class="w"> </span><span class="na">placeholder=</span><span class="s">&quot;请输入年龄..&quot;</span><span class="w"> </span><span class="na">value=</span><span class="s">&quot;</span><span class="k">&lt;%=</span><span class="n">stu</span><span class="p">.</span><span class="na">getAge</span><span class="p">()</span><span class="k">%&gt;</span><span class="s">&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-16-50" name="__codelineno-16-50"></a><span class="w">      </span><span class="nt">&lt;/div&gt;</span>
<a id="__codelineno-16-51" name="__codelineno-16-51"></a><span class="w">      </span><span class="nt">&lt;div&gt;</span>
<a id="__codelineno-16-52" name="__codelineno-16-52"></a><span class="w">        </span><span class="nt">&lt;label</span><span class="w"> </span><span class="na">for=</span><span class="s">&quot;dept&quot;</span><span class="nt">&gt;</span>所在系:<span class="nt">&lt;/label&gt;</span>
<a id="__codelineno-16-53" name="__codelineno-16-53"></a><span class="w">        </span><span class="nt">&lt;input</span><span class="w"> </span><span class="na">type=</span><span class="s">&quot;text&quot;</span><span class="w"> </span><span class="na">id=</span><span class="s">&quot;dept&quot;</span><span class="w"> </span><span class="na">name=</span><span class="s">&quot;dept&quot;</span><span class="w"> </span><span class="na">placeholder=</span><span class="s">&quot;请输入所在系..&quot;</span><span class="w"> </span><span class="na">value=</span><span class="s">&quot;</span><span class="k">&lt;%=</span><span class="n">stu</span><span class="p">.</span><span class="na">getDept</span><span class="p">()</span><span class="k">%&gt;</span><span class="s">&quot;</span><span class="nt">&gt;</span>
<a id="__codelineno-16-54" name="__codelineno-16-54"></a><span class="w">      </span><span class="nt">&lt;/div&gt;</span>
<a id="__codelineno-16-55" name="__codelineno-16-55"></a><span class="w">      </span><span class="nt">&lt;button</span><span class="w"> </span><span class="na">type=</span><span class="s">&quot;submit&quot;</span><span class="nt">&gt;</span>提交<span class="nt">&lt;/button&gt;</span>
<a id="__codelineno-16-56" name="__codelineno-16-56"></a><span class="w">    </span><span class="nt">&lt;/form&gt;</span>
<a id="__codelineno-16-57" name="__codelineno-16-57"></a><span class="w">  </span><span class="nt">&lt;/div&gt;</span>
<a id="__codelineno-16-58" name="__codelineno-16-58"></a><span class="nt">&lt;/body&gt;</span>
<a id="__codelineno-16-59" name="__codelineno-16-59"></a>
<a id="__codelineno-16-60" name="__codelineno-16-60"></a><span class="nt">&lt;/html&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建修改页面<code>webapp/stu/update.jsp</code>实现修改功能，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/stu/update.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-17-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-17-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-17-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-17-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-17-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-17-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-17-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-17-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-17-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-17-10">10</a></span>
<span class="normal"><a href="#__codelineno-17-11">11</a></span>
<span class="normal"><a href="#__codelineno-17-12">12</a></span>
<span class="normal"><a href="#__codelineno-17-13">13</a></span>
<span class="normal"><a href="#__codelineno-17-14">14</a></span>
<span class="normal"><a href="#__codelineno-17-15">15</a></span>
<span class="normal"><a href="#__codelineno-17-16">16</a></span>
<span class="normal"><a href="#__codelineno-17-17">17</a></span>
<span class="normal"><a href="#__codelineno-17-18">18</a></span>
<span class="normal"><a href="#__codelineno-17-19">19</a></span>
<span class="normal"><a href="#__codelineno-17-20">20</a></span>
<span class="normal"><a href="#__codelineno-17-21">21</a></span>
<span class="normal"><a href="#__codelineno-17-22">22</a></span>
<span class="normal"><a href="#__codelineno-17-23">23</a></span>
<span class="normal"><a href="#__codelineno-17-24">24</a></span>
<span class="normal"><a href="#__codelineno-17-25">25</a></span>
<span class="normal"><a href="#__codelineno-17-26">26</a></span>
<span class="normal"><a href="#__codelineno-17-27">27</a></span>
<span class="normal"><a href="#__codelineno-17-28">28</a></span>
<span class="normal"><a href="#__codelineno-17-29">29</a></span>
<span class="normal"><a href="#__codelineno-17-30">30</a></span>
<span class="normal"><a href="#__codelineno-17-31">31</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-17-1" name="__codelineno-17-1"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;stu.Student&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-17-2" name="__codelineno-17-2"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;java.util.ArrayList&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-17-3" name="__codelineno-17-3"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;java.util.List&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-17-4" name="__codelineno-17-4"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">contentType</span><span class="o">=</span><span class="s">&quot;text/html;charset=utf-8&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-17-5" name="__codelineno-17-5"></a><span class="k">&lt;%</span>
<a id="__codelineno-17-6" name="__codelineno-17-6"></a><span class="w">  </span><span class="n">Student</span><span class="w"> </span><span class="n">stu_new</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Student</span><span class="p">();</span>
<a id="__codelineno-17-7" name="__codelineno-17-7"></a>
<a id="__codelineno-17-8" name="__codelineno-17-8"></a><span class="w">  </span><span class="c1">//获取表单数据</span>
<a id="__codelineno-17-9" name="__codelineno-17-9"></a><span class="w">  </span><span class="n">stu_new</span><span class="p">.</span><span class="na">setNo</span><span class="p">(</span><span class="n">request</span><span class="p">.</span><span class="na">getParameter</span><span class="p">(</span><span class="s">&quot;no&quot;</span><span class="p">));</span>
<a id="__codelineno-17-10" name="__codelineno-17-10"></a><span class="w">  </span><span class="n">stu_new</span><span class="p">.</span><span class="na">setName</span><span class="p">(</span><span class="n">request</span><span class="p">.</span><span class="na">getParameter</span><span class="p">(</span><span class="s">&quot;name&quot;</span><span class="p">));</span><span class="w"> </span>
<a id="__codelineno-17-11" name="__codelineno-17-11"></a><span class="w">  </span><span class="n">stu_new</span><span class="p">.</span><span class="na">setGender</span><span class="p">(</span><span class="n">request</span><span class="p">.</span><span class="na">getParameter</span><span class="p">(</span><span class="s">&quot;gender&quot;</span><span class="p">));</span><span class="w"> </span>
<a id="__codelineno-17-12" name="__codelineno-17-12"></a><span class="w">  </span><span class="k">try</span><span class="p">{</span>
<a id="__codelineno-17-13" name="__codelineno-17-13"></a><span class="w">    </span><span class="n">stu_new</span><span class="p">.</span><span class="na">setAge</span><span class="p">(</span><span class="n">Integer</span><span class="p">.</span><span class="na">parseInt</span><span class="p">(</span><span class="n">request</span><span class="p">.</span><span class="na">getParameter</span><span class="p">(</span><span class="s">&quot;age&quot;</span><span class="p">)));</span><span class="w"> </span>
<a id="__codelineno-17-14" name="__codelineno-17-14"></a><span class="w">  </span><span class="p">}</span><span class="k">catch</span><span class="p">(</span><span class="n">Exception</span><span class="w"> </span><span class="n">e</span><span class="p">){</span>
<a id="__codelineno-17-15" name="__codelineno-17-15"></a>
<a id="__codelineno-17-16" name="__codelineno-17-16"></a><span class="w">  </span><span class="p">}</span>
<a id="__codelineno-17-17" name="__codelineno-17-17"></a><span class="w">  </span><span class="n">stu_new</span><span class="p">.</span><span class="na">setDept</span><span class="p">(</span><span class="n">request</span><span class="p">.</span><span class="na">getParameter</span><span class="p">(</span><span class="s">&quot;dept&quot;</span><span class="p">));</span><span class="w"> </span>
<a id="__codelineno-17-18" name="__codelineno-17-18"></a>
<a id="__codelineno-17-19" name="__codelineno-17-19"></a><span class="w">  </span><span class="n">List</span><span class="o">&lt;</span><span class="n">Student</span><span class="o">&gt;</span><span class="w"> </span><span class="n">students</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">List</span><span class="o">&lt;</span><span class="n">Student</span><span class="o">&gt;</span><span class="p">)</span><span class="n">session</span><span class="p">.</span><span class="na">getAttribute</span><span class="p">(</span><span class="s">&quot;stu_list&quot;</span><span class="p">);</span>
<a id="__codelineno-17-20" name="__codelineno-17-20"></a><span class="w">  </span><span class="k">if</span><span class="p">(</span><span class="n">students</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">null</span><span class="p">){</span>
<a id="__codelineno-17-21" name="__codelineno-17-21"></a><span class="w">    </span><span class="k">for</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="n">students</span><span class="p">.</span><span class="na">size</span><span class="p">();</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
<a id="__codelineno-17-22" name="__codelineno-17-22"></a><span class="w">        </span><span class="k">if</span><span class="p">(</span><span class="n">stu_new</span><span class="p">.</span><span class="na">getNo</span><span class="p">().</span><span class="na">equals</span><span class="p">(</span><span class="n">students</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">i</span><span class="p">).</span><span class="na">getNo</span><span class="p">())){</span>
<a id="__codelineno-17-23" name="__codelineno-17-23"></a><span class="w">          </span><span class="n">students</span><span class="p">.</span><span class="na">set</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">stu_new</span><span class="p">);</span>
<a id="__codelineno-17-24" name="__codelineno-17-24"></a><span class="w">          </span><span class="k">break</span><span class="p">;</span>
<a id="__codelineno-17-25" name="__codelineno-17-25"></a><span class="w">        </span><span class="p">}</span>
<a id="__codelineno-17-26" name="__codelineno-17-26"></a><span class="w">      </span><span class="p">}</span>
<a id="__codelineno-17-27" name="__codelineno-17-27"></a><span class="w">  </span><span class="p">}</span>
<a id="__codelineno-17-28" name="__codelineno-17-28"></a>
<a id="__codelineno-17-29" name="__codelineno-17-29"></a><span class="w">  </span><span class="c1">//操作完成，回到列表</span>
<a id="__codelineno-17-30" name="__codelineno-17-30"></a><span class="w">  </span><span class="n">response</span><span class="p">.</span><span class="na">sendRedirect</span><span class="p">(</span><span class="n">String</span><span class="p">.</span><span class="na">format</span><span class="p">(</span><span class="s">&quot;%s%s&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">request</span><span class="p">.</span><span class="na">getContextPath</span><span class="p">(),</span><span class="w"> </span><span class="s">&quot;/stu/list.jsp&quot;</span><span class="p">));</span>
<a id="__codelineno-17-31" name="__codelineno-17-31"></a><span class="k">%&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
<li>
<p>创建删除页面<code>webapp/stu/delete.jsp</code>实现删除功能，参考代码如下：</p>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">BuiltInTest/src/main/webapp/stu/delete.jsp</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-18-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-18-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-18-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-18-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-18-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-18-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-18-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-18-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-18-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-18-10">10</a></span>
<span class="normal"><a href="#__codelineno-18-11">11</a></span>
<span class="normal"><a href="#__codelineno-18-12">12</a></span>
<span class="normal"><a href="#__codelineno-18-13">13</a></span>
<span class="normal"><a href="#__codelineno-18-14">14</a></span>
<span class="normal"><a href="#__codelineno-18-15">15</a></span>
<span class="normal"><a href="#__codelineno-18-16">16</a></span>
<span class="normal"><a href="#__codelineno-18-17">17</a></span>
<span class="normal"><a href="#__codelineno-18-18">18</a></span>
<span class="normal"><a href="#__codelineno-18-19">19</a></span>
<span class="normal"><a href="#__codelineno-18-20">20</a></span>
<span class="normal"><a href="#__codelineno-18-21">21</a></span>
<span class="normal"><a href="#__codelineno-18-22">22</a></span>
<span class="normal"><a href="#__codelineno-18-23">23</a></span>
<span class="normal"><a href="#__codelineno-18-24">24</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-18-1" name="__codelineno-18-1"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;java.util.ArrayList&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-18-2" name="__codelineno-18-2"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;java.util.List&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-18-3" name="__codelineno-18-3"></a><span class="k">&lt;%@</span><span class="w"> </span><span class="n">page</span><span class="w"> </span><span class="n">import</span><span class="o">=</span><span class="s">&quot;stu.Student&quot;</span><span class="w"> </span><span class="n">contentType</span><span class="o">=</span><span class="s">&quot;text/html;charset=utf-8&quot;</span><span class="w"> </span><span class="k">%&gt;</span>
<a id="__codelineno-18-4" name="__codelineno-18-4"></a><span class="k">&lt;%</span>
<a id="__codelineno-18-5" name="__codelineno-18-5"></a><span class="w">  </span><span class="n">String</span><span class="w"> </span><span class="n">no</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">request</span><span class="p">.</span><span class="na">getParameter</span><span class="p">(</span><span class="s">&quot;no&quot;</span><span class="p">);</span>
<a id="__codelineno-18-6" name="__codelineno-18-6"></a><span class="w">  </span><span class="n">List</span><span class="o">&lt;</span><span class="n">Student</span><span class="o">&gt;</span><span class="w"> </span><span class="n">students</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">List</span><span class="o">&lt;</span><span class="n">Student</span><span class="o">&gt;</span><span class="p">)</span><span class="n">session</span><span class="p">.</span><span class="na">getAttribute</span><span class="p">(</span><span class="s">&quot;stu_list&quot;</span><span class="p">);</span>
<a id="__codelineno-18-7" name="__codelineno-18-7"></a><span class="w">  </span><span class="k">if</span><span class="p">(</span><span class="n">students</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">null</span><span class="p">){</span>
<a id="__codelineno-18-8" name="__codelineno-18-8"></a><span class="w">    </span><span class="c1">//检索待删除学生的索引</span>
<a id="__codelineno-18-9" name="__codelineno-18-9"></a><span class="w">    </span><span class="kt">int</span><span class="w"> </span><span class="n">no_index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span><span class="p">;</span>
<a id="__codelineno-18-10" name="__codelineno-18-10"></a><span class="w">    </span><span class="k">for</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="n">students</span><span class="p">.</span><span class="na">size</span><span class="p">();</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
<a id="__codelineno-18-11" name="__codelineno-18-11"></a><span class="w">      </span><span class="k">if</span><span class="p">(</span><span class="n">no</span><span class="p">.</span><span class="na">equals</span><span class="p">(</span><span class="n">students</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">i</span><span class="p">).</span><span class="na">getNo</span><span class="p">())){</span>
<a id="__codelineno-18-12" name="__codelineno-18-12"></a><span class="w">        </span><span class="n">no_index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">i</span><span class="p">;</span>
<a id="__codelineno-18-13" name="__codelineno-18-13"></a><span class="w">        </span><span class="k">break</span><span class="p">;</span>
<a id="__codelineno-18-14" name="__codelineno-18-14"></a><span class="w">      </span><span class="p">}</span>
<a id="__codelineno-18-15" name="__codelineno-18-15"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-18-16" name="__codelineno-18-16"></a>
<a id="__codelineno-18-17" name="__codelineno-18-17"></a><span class="w">    </span><span class="k">if</span><span class="p">(</span><span class="n">no_index</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span><span class="p">){</span>
<a id="__codelineno-18-18" name="__codelineno-18-18"></a><span class="w">      </span><span class="n">students</span><span class="p">.</span><span class="na">remove</span><span class="p">(</span><span class="n">no_index</span><span class="p">);</span>
<a id="__codelineno-18-19" name="__codelineno-18-19"></a><span class="w">    </span><span class="p">}</span>
<a id="__codelineno-18-20" name="__codelineno-18-20"></a><span class="w">  </span><span class="p">}</span>
<a id="__codelineno-18-21" name="__codelineno-18-21"></a>
<a id="__codelineno-18-22" name="__codelineno-18-22"></a><span class="w">  </span><span class="c1">//操作完成，回到列表</span>
<a id="__codelineno-18-23" name="__codelineno-18-23"></a><span class="w">  </span><span class="n">response</span><span class="p">.</span><span class="na">sendRedirect</span><span class="p">(</span><span class="n">String</span><span class="p">.</span><span class="na">format</span><span class="p">(</span><span class="s">&quot;%s%s&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">request</span><span class="p">.</span><span class="na">getContextPath</span><span class="p">(),</span><span class="w"> </span><span class="s">&quot;/stu/list.jsp&quot;</span><span class="p">));</span>
<a id="__codelineno-18-24" name="__codelineno-18-24"></a><span class="k">%&gt;</span>
</code></pre></div></td></tr></table></div>
</li>
</ol>
<h3 id="_3">拓展练习</h3>
<ol>
<li>使用JSP实现课程表的增、删、改、查操作</li>
</ol>












                
              </article>
            </div>
          
          
  <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script>

<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
        </div>
        
      </main>
      
        <footer class="md-footer">
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-copyright">
  
  
    Made with
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
      Material for MkDocs
    </a>
  
</div>
      
    </div>
  </div>
</footer>
      
    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    
    
    <script id="__config" type="application/json">{"base": "../..", "features": ["content.code.copy", "content.tabs.link", "navigation.expand", "navigation.sections", "navigation.path"], "search": "../../assets/javascripts/workers/search.f8cc74c7.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script>
    
    
      <script src="../../assets/javascripts/bundle.f1b6f286.min.js"></script>
      
    
  </body>
</html>